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 ...
随机推荐
- GCD多线程 在子线程中获取网络图片 在主线程更新
子线程中得所有数据都可以直接拿到主线程中使用 //当触摸屏幕的时候,从网络上下载一张图片到控制器的view上显示 -(void)touchesBegan:(NSSet *)touches withEv ...
- angularJS学习笔记二
angularJS四个特性 1.MVC <!doctype html> <html ng-app> <head> <meta charset="ut ...
- Echop后台分页实现原理详解
ecshop后台开发,工作中分页中遇到的问题 1.通过筛选条件筛选出数据后,点击下一页返回没有筛选(所有数据)的第二页数据 效果 结果 点击分页后效果 问题:ecshop分页利用ajax实现,在点击下 ...
- JS定义对象方法?
第一种:构造函数形式 把参数作为构造函数的参数传递,这样对于对象的初始化更灵活一点 <script language="javascript"><!-- /** ...
- django+nginx+supervisor+gunicorn+gevent 网站部署
django+nginx+supervisor+gunicorn+gevent 网站部署 django,nginx,supervisor,gunicorn,gevent这几个都是在本领域大名鼎鼎的软件 ...
- light oj 1248 第六周E题(期望)
E - 期望(经典问题) Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Descri ...
- 【PRO ASP.NE MVC4 学习札记】使用Moq辅助进行单元测试
清楚问题所在: 先开个头,当我们对A进行单元测试时,可能会发现A的实现必须要依赖B.这时,我们在写单元测试时,就必须先创建B的实例,然后把B传给A再建立A的实例进行测试. 这样就会出现一些问题: 1. ...
- Redis系列(1)之安装
Redis系列(1)之安装 由于项目的需要,最近需要研究下Redis.Redis是个很轻量级的NoSql内存数据库,它有多轻量级的呢,用C写的,源码只有3万行,空的数据库只占1M内存.它的功能很丰富, ...
- 转:windows xp下如何安装SQL server2000企业版
SQL2000企业版本 适用于WIN 2000 Server系统和Windows 2003系统,Windows XP一般装不了需要选用个人版或开发板.但是企业版也可以安装在xp系统下.这里介绍一个XP ...
- cf C. Counting Kangaroos is Fun
http://codeforces.com/contest/373/problem/C 贪心,先排序,然后从n/2位置倒着找每一个可不可以放到别的袋鼠内. #include <cstdio> ...