struts开发<struts中的action具体配置. 二>
2014-07-18 22:20
211 查看
在eclipse中新建项目StrutsDemo1【struts的配置见】struts开发<在eclipse中配置struts. 一>
具体目录结构如下
第一种配置方法
新建UserAction
在struts重配置
新建input.jsp 、list.jsp、add.jsp
运行tomcat,在浏览器输入http://localhost:9000/strustDemo1/input
同理输入响应的目录就会得到相应的页面输出
第二种配置方法
其他的不用改动,直接改动UserAction和struts.xml即可
运行时输入http://localhost:9000/StrutsDemo2/User!add 即可得到相应的页面
第三种方法
通过通配符配置,通配符不来了解的自行百度
action的配置方法大概就这三种,后两种在开发中用的比较多
具体目录结构如下
第一种配置方法
新建UserAction
package fzl.user.struts.demo; import com.opensymphony.xwork2.ActionSupport; public class UserAction extends ActionSupport { public String list(){ System.out.println("list"); return "success"; } public String input(){ System.out.println("input"); return "success"; } public String add(){ System.out.println("add"); return "success"; }}
在struts重配置
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <package name="default" namespace="/" extends="struts-default"> <!-- 第一种,配置多个action --> <action name="add" class="fzl.user.struts.demo.UserAction" method="add"> <result name="success">/WEB-INF/User/add.jsp</result> </action> <action name="input" class="fzl.user.struts.demo.UserAction" method="input"> <result name="success">/WEB-INF/User/input.jsp</result> </action> <action name="list" class="fzl.user.struts.demo.UserAction" method="list"> <result name="success">/WEB-INF/User/list.jsp</result> </action> </package> </struts>
新建input.jsp 、list.jsp、add.jsp
<%@ 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>Insert title here</title> </head> <body> <h1>------------------input-----------------</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>Insert title here</title> </head> <body> <h1>------------------add-----------------</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>Insert title here</title> </head> <body> <h1>------------------list-----------------</h1> </body> </html>
运行tomcat,在浏览器输入http://localhost:9000/strustDemo1/input
同理输入响应的目录就会得到相应的页面输出
第二种配置方法
其他的不用改动,直接改动UserAction和struts.xml即可
package fzl.user.struts.demo; import com.opensymphony.xwork2.ActionSupport; public class UserAction extends ActionSupport { public String list(){ System.out.println("list"); return "list"; } public String input(){ System.out.println("input"); return "input"; } public String add(){ System.out.println("add"); return "add"; }}
<action name="User" class="fzl.struts.demo.UserAction"> <result name="add">/WEB-INF/User/list.jsp</result> <result name="input">/WEB-INF/User/input.jsp</result> <result name="list">/WEB-INF/User/add.jsp</result> </action>
运行时输入http://localhost:9000/StrutsDemo2/User!add 即可得到相应的页面
第三种方法
package fzl.user.struts.demo; import com.opensymphony.xwork2.ActionSupport; public class UserAction extends ActionSupport { public String list(){ System.out.println("list"); return "success"; } public String input(){ System.out.println("input"); return "success"; } public String add(){ System.out.println("add"); return "success"; }}
通过通配符配置,通配符不来了解的自行百度
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <package name="default" namespace="/" extends="struts-default"> <action name="*_*" class="fzl.user.struts.demo.{1}Action" method="{2}"> <result>/WEB-INF/{1}/{2}.jsp</result> </action> </package> </struts>
action的配置方法大概就这三种,后两种在开发中用的比较多
相关文章推荐
- struts开发<在eclipse中配置struts. 一>
- struts2配置常量<constant name="struts.devMode">,将值修改为true(开发模式有什么好处)的好处
- struts开发<struts中的action详细配置. 二>
- Struts2通配符映射/Struts <action name="/*/*" method="{2}" class="com.jxc.action.{1}Action"> <result
- struts-config.xml中action配置--> attribute和name的区别(转)
- 5.Struts的<action input=""></action>:struts-config.xml
- struts <s:action>标签的用法
- 防止页面表单重复提交,JSP页面加入 <s:token/> 以及Struts的相关配置详解
- struts2配置常量<constant name="struts.devMode">,将值修改为true(开发模式有什么好处)的好处
- struts-config.xml中action配置 --> attribute和name的区别
- 2.Struts的<action forward="/login.jsp"></action>:struts-config.xml
- spring mvc 的配置 (mvc 和servlet<action>的配置)
- <Action>和<result>配置中的各项默认值
- 2.Struts的<action input=""></action>:ActionForm
- struts.xml配置文件中result的语法:<result name="" type="">xxxxx</result>
- scala在eclipse开发环境配置<转>
- struts <s:action>标签的用法
- struts2配置常量<constant name="struts.devMode">,将值修改为true(开发模式有什么好处)的好处
- Struts标签<s:action>的使用详解
- Revit 二次开发的环境配置<上手版>