在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开发&lt;struts中的action详细配置. 二&gt;的更多相关文章

  1. Apache中AllowOverride的详细配置使用

    我们通常利用Apache的rewrite模块对URL进行重写,rewrite规则会写在 .htaccess 文件里.但要使 apache 能够正常的读取.htaccess 文件的内容,就必须对.hta ...

  2. struts开发&lt;struts中的參数传递.三&gt;

    不说废话,直接上干货 1.通过set和get传递參数 添加username 和password两个属性并添加set和get方法 package fzl.user.struts.demo; import ...

  3. [Intel Edison开发板] 06、Edison开发在linux中烧写、配置、搭建开发环境

    1.前言 linux上烧写.配置.搭建Edison环境,千万不要用默认的setup tool for ubuntu!!! (即使,你用的就是ubuntu) 因为,其默认的工具会从一个坏链接下载配置文件 ...

  4. phpstormn 中 xdebug 的详细配置2

    配置PHPStorm 图1:首先配置PHP解释器的路径 图2:File>Settings>PHP>Servers,这里要填写服务器端的相关信息,name填localhost,host ...

  5. [转]struts1.2的action参数配置

    转载地址:http://chenfeng0104.iteye.com/blog/796870 <struts-config>     <form-beans>         ...

  6. 【转】struts1.2的action参数配置

    转载地址:http://chenfeng0104.iteye.com/blog/796870 <struts-config>     <form-beans>         ...

  7. struts2 codebehind + actionPackages 实现Action零配置

    1.jar包:struts2-codebehind-plugin-2.2.1.1.jar 2.struts.xml:<!-- codebehind中查找action的返回结果资源时的默认文件夹 ...

  8. javaWeb中struts开发——helloworld

    1.新建一个web项目 2.选中project,右键,选择MyElcipse,选择add  struts capab...添加struts支持,然后自己命名包 3.Struts在建立jsp时,标签要到 ...

  9. 通常Struts框架会自动地从action mapping中创建action对象

    开发者不必在Spring中去注册action,尽管可以这么去做,通常Struts框架会自动地从action mapping中创建action对象 struts2-spring-plugin-x-x-x ...

随机推荐

  1. 二、T4模板

    上文带大家见识了下T4,这里呢开始介绍T4模板有关的内容.关于T4模板介绍和使用网上一搜一箩筐,想深入研究的可以自行去找些资料,这里只介绍接下来我们需要使用的一些知识,不会面面俱到的讲T4模板所有的知 ...

  2. 安装php时,make步骤报错make: *** [ext/gd/gd.lo] Error 1

    安装PHP时,make步骤报错make: *** [ext/gd/gd.lo] Error 1 /usr/local/src/LAMP+memcahed+catci/php-5.4.0/ext/gd/ ...

  3. openssl提取pfx证书密钥对

    刚做银联的项目,对方给了1.pfx和1.cer两个测试文件,总结一下利用这两个文件提取出文本 银联提供两个测试证书  1.pfx 和 1.cer . 其中 pfx证书包含RSA的公钥和密钥;cer证书 ...

  4. 【USACO 1.4.3】等差数列

    [题目描述] 一个等差数列是一个能表示成a, a+b, a+2b,..., a+nb (n=0,1,2,3,...)的数列. 在这个问题中a是一个非负的整数,b是正整数.写一个程序来找出在双平方数集合 ...

  5. bc命令详解与实例

    bc: bc 是一种高精度的可交互执行的计算机语言.它在一些浮点数的运算中应用广泛. 一般情况下我们直接输入 bc ,便可进入其工作环境.当然,它还有其他的参数 -h 显示帮助信息并退出 -i 强制进 ...

  6. phpcms v9自定义表单提交后返回上一页实现方法

    PHPcms v9中提交自定义表单后默认都是回到首页的,是不是感觉很不爽! 接下来,就说下phpcms v9自定义表单提交后返回上一页实现方法. 1.找到这个文件 phpcms\modules\for ...

  7. 88 Merge Sorted Array(归并排序Easy)

    题目意思:num1和num2均为递增数组,对其进行递增排序存到num1中 class Solution { public: void merge(vector<int>& nums ...

  8. 委托异步调用时BeginInvoke的陷阱处理

    这个陷阱来自于一个需求:需要异步在后台处理数据,处理完后触发处理完成的事件,大概是这么写的: EmployeeCollection data = new EmployeeCollection(): d ...

  9. C语言笔记(结构体与offsetof、container_of之前的关系)

    关于结构体学习,需要了解:结构体的定义和使用.内存对齐.结构体指针.得到结构体元素的偏移量(offsetof宏实现) 一.复习结构体的基本定义和使用 typedef struct mystruct { ...

  10. HDU 3551 Hard Problem

    http://acm.hdu.edu.cn/showproblem.php?pid=3551 题意:给出一个图,还有一个子图的度数,求有没有办法通过删边使得原图的度数变成那个子图的度数? 思路:我们考 ...