struts2 注解 demo2
来源:互联网 发布:google linux翻墙插件 编辑:程序博客网 时间:2024/05/20 14:24
1 必须引入struts2-convention-plugin-2.1.6包
2 WelcomeUserAction 类要放在 action命名的包下 并要用*Action 来命名类
3 successPage.jsp要放在web-inf/results目录下 这个是在struts.properties 根据struts.convention.result.path=/results来配置的
一搭建环境
jdk1.6 struts2.1.6 tomcat6.0
所需包
01.commons-fileupload-1.2.1
02.commons-io-1.3.2
03.commons-logging-1.1
04.freemarker-2.3.13
05.junit-3.8.1
06.ognl-2.6.11
07.spring-test-2.5.6
08.struts2-convention-plugin-2.1.6
09.struts2-core-2.1.6
10.xwork-2.1.2
二代码
web.xml
WelcomeUserAction.java
index.jsp在web-info下
successPage.jsp 在web-inf/results
struts.properties
2 WelcomeUserAction 类要放在 action命名的包下 并要用*Action 来命名类
3 successPage.jsp要放在web-inf/results目录下 这个是在struts.properties 根据struts.convention.result.path=/results来配置的
一搭建环境
jdk1.6 struts2.1.6 tomcat6.0
所需包
01.commons-fileupload-1.2.1
02.commons-io-1.3.2
03.commons-logging-1.1
04.freemarker-2.3.13
05.junit-3.8.1
06.ognl-2.6.11
07.spring-test-2.5.6
08.struts2-convention-plugin-2.1.6
09.struts2-core-2.1.6
10.xwork-2.1.2
二代码
web.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
- id="WebApp_ID" version="2.5">
- <display-name>Struts2_Annotations2</display-name>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- <filter>
- <filter-name>struts2</filter-name>
- <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- </web-app>
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"id="WebApp_ID" version="2.5"><display-name>Struts2_Annotations2</display-name><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class></filter><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping></web-app>
WelcomeUserAction.java
- package com.test.action;
- import org.apache.struts2.convention.annotation.Action;
- import org.apache.struts2.convention.annotation.Result;
- public class WelcomeUserAction
- {
- private String userName;
- private String message;
- @Action(value ="/welcome", results = { @Result(name ="success", location = "/results/successPage.jsp") })
- public String execute()
- {
- message = "Welcome " + userName +" !";
- return "success";
- }
- public String getUserName()
- {
- return userName;
- }
- public void setUserName(String userName)
- {
- this.userName = userName;
- }
- public String getMessage()
- {
- return message;
- }
- public void setMessage(String message)
- {
- this.message = message;
- }
- }
package com.test.action;import org.apache.struts2.convention.annotation.Action;import org.apache.struts2.convention.annotation.Result;public class WelcomeUserAction{ private String userName; private String message; @Action(value = "/welcome", results = { @Result(name = "success", location = "/results/successPage.jsp") }) public String execute() { message = "Welcome " + userName + " !"; return "success"; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; }}
index.jsp在web-info下
- <%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8"%>
- <%@ taglib uri="/struts-tags" prefix="s"%>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Annotations1</title>
- </head>
- <body>
- <body>
- <s:form action="welcome">
- <s:textfield name="userName" label="User Name" />
- <s:submit />
- </s:form>
- </body>
- </html>
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><%@ taglib uri="/struts-tags" prefix="s"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Annotations1</title></head><body><body><s:form action="welcome"><s:textfield name="userName" label="User Name" /><s:submit /></s:form></body></html>
successPage.jsp 在web-inf/results
- <%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8"%>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Welcome User</title>
- </head>
- <body>
- <h1>${message}</h1>
- </body>
- </html>
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Welcome User</title></head><body><h1>${message}</h1></body></html>
struts.properties
- struts.convention.result.path=/results
- struts2 注解 demo2
- Demo2
- DEMO2
- demo2
- Demo2
- struts2注解
- struts2注解
- struts2 注解
- struts2 注解
- struts2注解
- struts2注解
- struts2注解
- struts2注解
- Struts2注解
- struts2注解
- struts2注解
- struts2注解
- struts2注解
- 操作文件夹或文件的权限的命令行工具Icacls
- Android UI开发第二十八篇——Fragment中使用左右滑动菜单
- redis应用—缓存
- 茎叶图
- MySQL数据库引擎介绍、区别、创建和性能测试
- struts2 注解 demo2
- USB开发学习日记-01
- ProgressBar 圆形进度条颜色的设置
- Deleting rows in table view Checklist
- org.springframeword.util.Asert用法
- DevExpress 如何使用外键
- struts2的注解功能
- 关于tomcat一点细节
- 小笔记,在windows和linux下分开编译、在C\C++下都使用C风格编译