struts开发<struts中的action详细配置. 二>
在eclipse中新建项目StrutsDemo1【struts的配置见】struts开发<在eclipse中配置struts. 一>
详细文件夹结构例如以下
第一种配置方法
新建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开发<struts中的action详细配置. 二>的更多相关文章
- Apache中AllowOverride的详细配置使用
我们通常利用Apache的rewrite模块对URL进行重写,rewrite规则会写在 .htaccess 文件里.但要使 apache 能够正常的读取.htaccess 文件的内容,就必须对.hta ...
- struts开发<struts中的參数传递.三>
不说废话,直接上干货 1.通过set和get传递參数 添加username 和password两个属性并添加set和get方法 package fzl.user.struts.demo; import ...
- [Intel Edison开发板] 06、Edison开发在linux中烧写、配置、搭建开发环境
1.前言 linux上烧写.配置.搭建Edison环境,千万不要用默认的setup tool for ubuntu!!! (即使,你用的就是ubuntu) 因为,其默认的工具会从一个坏链接下载配置文件 ...
- phpstormn 中 xdebug 的详细配置2
配置PHPStorm 图1:首先配置PHP解释器的路径 图2:File>Settings>PHP>Servers,这里要填写服务器端的相关信息,name填localhost,host ...
- [转]struts1.2的action参数配置
转载地址:http://chenfeng0104.iteye.com/blog/796870 <struts-config> <form-beans> ...
- 【转】struts1.2的action参数配置
转载地址:http://chenfeng0104.iteye.com/blog/796870 <struts-config> <form-beans> ...
- struts2 codebehind + actionPackages 实现Action零配置
1.jar包:struts2-codebehind-plugin-2.2.1.1.jar 2.struts.xml:<!-- codebehind中查找action的返回结果资源时的默认文件夹 ...
- javaWeb中struts开发——helloworld
1.新建一个web项目 2.选中project,右键,选择MyElcipse,选择add struts capab...添加struts支持,然后自己命名包 3.Struts在建立jsp时,标签要到 ...
- 通常Struts框架会自动地从action mapping中创建action对象
开发者不必在Spring中去注册action,尽管可以这么去做,通常Struts框架会自动地从action mapping中创建action对象 struts2-spring-plugin-x-x-x ...
随机推荐
- iOS开发中常用的宏
前言 今天将一些简化工程代码的宏定义拿出来分享一下,自定义一些宏可以有效的简化代码,提高编码效率. Application #define APPLICATION [UIApplication sha ...
- sencha app build 到 Capturing theme image不执行
解决sencha app build 到 Capturing theme image不执行 今天电脑重装系统,重新安装了sencha cmd,但是在打包时,到了 Capturing theme ima ...
- Android开发-解决 AIDL 中找不到couldn't find import for class错误
最近在使用AIDL做IPC的时候,在处理复杂的数据类型的时候,编译器总是报couldn't find import for class错误,所以在这里总结下AIDL使用的时候的一些注意事项,希望对你能 ...
- js join()函数将数组转换成字符串
join() 方法用于把数组中的所有元素放入一个字符串.作用是将数组转换为字符串,其作用和toString()相同. 元素是通过指定的分隔符进行分隔的. 例如: var asp=['H','ell', ...
- XmlHttp对象
我是这样理解XmlHttp对象的:xml是一种文档类型Http可以把它看做是浏览器XmlHttp:可以解释为把xml的内容读到浏览器上(网页上),把这句话封装一下,见下XmlHttp是浏览器对象,起的 ...
- SQL2008数据库连接服务器为主机名时连接成功,服务器为Ip地址时链接失败
如图:
- TCP回射服务器程序:str_echo函数
str_echo函数执行处理每个客户的服务: 从客户读入数据,并把它们回射给客户 读入缓冲区并回射其中内容: read函数从套接字读入数据,writen函数把其中内容回射给客户 如果客户关闭连接,那么 ...
- listview底部增加按钮
View bottomView=getActivity().getLayoutInflater().inflate(R.layout.btn_my_course, null); myCourses = ...
- REST服务中的日志可视化(关键技术实现)
引言 在系统构建完成之后,我们通常会使用REST API对外提供服务,在REST API的处理过程中经常会出现一些异想不到的问题(用户权限不足.参数不全.数据库访问异常等),导致请求失败,很多时候用户 ...
- HTML5 Web socket和socket.io
what is websockets Two-way communication over ont TCP socket, a type of PUSH technology HTML5的新特性,用于 ...