在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. react服务端渲染(同构)

    学习react也有一段时间了,使用react后首页渲染的速度与seo一直不理想.打算研究一下react神奇服务端渲染. react服务端渲染只能使用nodejs做服务端语言实现前后端同构,在后台对re ...

  2. Hive学习之一 《Hive的介绍和安装》

    一.什么是Hive Hive是建立在 Hadoop 上的数据仓库基础构架.它提供了一系列的工具,可以用来进行数据提取转化加载(ETL),这是一种可以存储.查询和分析存储在 Hadoop 中的大规模数据 ...

  3. _Obj* __STL_VOLATILE* __my_free_list

    今天在读<STL源码剖析>空间配置器第二级时看到了这句,有点不解,于是查阅后知: obj后面是个指针 STL_VOLATILE也应该是个类型定义的吧,程序中应该有define来对它定义.所 ...

  4. 安卓应用开发用户体验之禁止EditText自动获取焦点

    一.问题描述: 在安卓应用开发时,经常会在同一个页面有许多不同的控件,在用户操作时,如何正确的在这些控件之间来回切换是良好用户体验的重要问题.可能会碰到如下问题:在点击页面内某控件时(假设控件为Spi ...

  5. Hibernate4 clob字段存取

    domain的字段: private Clob content; hibernate的xml映射 <property name="content" type="cl ...

  6. matplotlib入门--1(条形图, 直方图, 盒须图, 饼图)

    作图首先要进行数据的输入,matplotlib包只提供作图相关功能,本身并没有数据读入.输出函数,针对各种试验或统计文本数据输入可以使用numpy提供的数据输入函数. # -*- coding: gb ...

  7. jquery获取浏览器的高度和宽度

    <script type="text/javascript"> $(document).ready(function() { alert($(window).heigh ...

  8. codevs 3269 混合背包

    题目描述 Description 背包体积为V ,给出N个物品,每个物品占用体积为Vi,价值为Wi,每个物品要么至多取1件,要么至多取mi件(mi > 1) , 要么数量无限 , 在所装物品总体 ...

  9. GIS

    def GIS(): global C global FeaWeights for wid in WordDic.keys(): FeaWeights[wid] = {} for classid in ...

  10. 理解 Javascript 的闭包

    什么是闭包 闭包是什么?闭包是Closure,这是静态语言所不具有的一个新特性.但是闭包也不是什么复杂到不可理解的东西,简而言之,闭包就是: 闭包就是函数的局部变量集合,只是这些局部变量在函数返回后会 ...