欢迎访问成都祈钰瑶科技有限公司!

全国免费服务热线:

18982081108
✕

成都网站设计公司,成都响应式网站设计,成都移动端网站设计,成都网站UI设计

WebWork框架简单示例

1 先下载WebWork框架开发包http://www.opensymphony.com/webwork/download.action 我用的是2.2.4的.

洪雅ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为成都创新互联公司的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!

2 .在WebWork框架里建立一个WEB工程.你解压WebWork的开发包以后会发现有两个jar文件在***级目录里面,把他们拷贝进你的工程里面.然后你还会看见lib目录(webwork开发支持的所有jar文件),lib目录下面有个defult的目录,把这个目录里面的jar文件也都拷贝进你的工程,他们是开发webwork最基本的保障.

3 在src下创建两个文件.

(1)xwork.xml

 
 
 
  1. <!DOCTYPE xwork PUBLIC 
  2. "-//OpenSymphony Group//XWork 1.1.1//EN" 
  3. "http://www.opensymphony.com/xwork/xwork-1.1.1.dtd"> 
  4. <xwork> 
  5. <include file="webwork-default.xml" /> 
  6. <package name="webwork" extends="webwork-default"> 
  7. <action name="hello" class="helloworld.HelloWorldAction"> 
  8. <result name="yes" type="dispatcher">/yes.jsp
  9. </result> 
  10. </action> 
  11. </package> 
  12. </xwork> 

(2)webwork.properties

webwork.i18n.encoding=GBK

### Load custom property files (does not override webwork.properties!)

# added the MockTag to the path of Tags that the TagDirective will search through

webwork.velocity.tag.path = com.opensymphony.webwork.views.velocity.ui, org.displaytag.tags

webwork.ui.templateDir = template

### Load custom default resource bundles

### XSLT Cache

webwork.xslt.nocache = true

3 web.xml

 
 
 
  1. xml version="1.0" encoding="UTF-8"?>
  2. <web-app version="2.4" 
  3. xmlns="http://java.sun.com/xml/ns/j2ee" 
  4. xmlns:xsi="http://www.w3.org/2001/XML
  5. Schema-instance" 
  6. xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
  7. http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  8. <welcome-file-list>
  9. <welcome-file>index.jsp welcome-file>
  10. welcome-file-list>
  11. <servlet> 
  12. <servlet-name>webwork servlet-name> 
  13. <servlet-class> 
  14. com.opensymphony.webwork.dispatcher.ServletDispatcher 
  15. servlet-class> 
  16. servlet> 
  17. <servlet-mapping> 
  18. <servlet-name>webwork servlet-name> 
  19. <url-pattern>*.action url-pattern> 
  20. servlet-mapping> 
  21. web-app>

4 在WebWork框架中创建HelloWorldAction类在helloworld包下,填写代码如下:

 
 
 
  1. package helloworld; 
  2. import com.opensymphony.xwork.Action; 
  3. public class HelloWorldAction implements Action { 
  4. private String userName; 
  5. public String getUserName() { 
  6. return userName; 
  7. } 
  8. public void setUserName(String userName) { 
  9. this.userName = userName; 
  10. } 
  11. public String execute() throws Exception { 
  12. // 处理乱码 
  13. //userName = new String
  14. (userName.getBytes("iso-8859-1"),"GBK"); 
  15. System.out.println(userName); 
  16. return "yes"; 
  17. } 
  18. } 

5然后在创建下列两个jsp页面.

***个页面:index.jsp

 
 
 
  1. <%@ page language="java" import="java.util.*" 
  2. pageEncoding="GBK"%> 
  3. <% 
  4. String path = request.getContextPath(); 
  5. String basePath = request.getScheme()+":
  6. //"+request.getServerName()+":
  7. "+request.getServerPort()+path+"/"; 
  8. %> 
  9. <!DOCTYPE HTML PUBLIC 
  10. "-//W3C//DTD HTML 4.01 Transitional//EN"> 
  11. <html> 
  12. <head> 
  13. <base href="<%=basePath%>"> 
  14. <title>My JSP 'index.jsp' starting page
  15. </title> 
  16. <meta http-equiv="pragma" c> 
  17. <meta http-equiv="cache-control" c> 
  18. <meta http-equiv="expires" c>     
  19. <meta http-equiv="keywords" c> 
  20. <meta http-equiv="description" c> 
  21. <!-- 
  22. <link rel="stylesheet" type="text/css" 
  23. href="styles.css"> 
  24. --> 
  25. </head> 
  26. <body> 
  27. <form action="hello.action" method="post"> 
  28. <input type="text" name="userName"/> 
  29. <br> 
  30. <input type="submit"/> 
  31. </form> 
  32. </body> 
  33. </html>

第二个页面:yes.jsp

 
 
 
  1. <%@ page language="java" import="java.util.*" 
  2. pageEncoding="GBK"%> 
  3. <%@ taglib prefix = "ww" uri = "/webwork" %> 
  4. <% 
  5. String path = request.getContextPath(); 
  6. String basePath = request.getScheme()+":
  7. //"+request.getServerName()+":
  8. "+request.getServerPort()+path+"/"; 
  9. %> 
  10. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 
  11. Transitional//EN"> 
  12. <html> 
  13. <head> 
  14. <base href="<%=basePath%>"> 
  15. <title>My JSP 'yes.jsp' starting page</title> 
  16. <meta http-equiv="pragma" c> 
  17. <meta http-equiv="cache-control" c> 
  18. <meta http-equiv="expires" c>     
  19. <meta http-equiv="keywords" c> 
  20. <meta http-equiv="description" c> 
  21. <!-- 
  22. <link rel="stylesheet" type="text/css" 
  23. href="styles.css"> 
  24. --> 
  25. </head> 
  26. <body> 
  27. yes. <br> 
  28. <ww:property value="%{userName}"/> 
  29. </body> 
  30. </html>