`

strust2_003

阅读更多
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
	<constant name="struts.i18n.encoding" value="utf-8"></constant>
	<constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant>
	
	<package name="init" namespace="/init" extends="struts-default">
		<global-results>
			<result name="global">/global.jsp</result>
		</global-results>
	</package>
	
	<package name="user" namespace="/user" extends="init">
		
		<action name="userAction" class="action.UserAction">
			<!-- 转发到指定jsp -->
			<result name="ognl" type="dispatcher">/ognl.jsp</result>
			<!-- 重定向到指定jsp -->
			<result name="success" type="redirect">/success.jsp</result>
		</action>
	
	</package>
</struts>    



<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
	<package name="test" namespace="/test" extends="init">
		
		<action name="*Action" class="action.TestAction1" method="{1}">
			<!-- 转发到指定jsp -->
			<result name="dispatcher" type="dispatcher">/success.jsp</result>
			<!-- 重定向指定 jsp -->
			<result name="redirect" type="redirect">/success.jsp</result>
			<!-- 转发到指定Action -->
			<result name="chain" type="chain">dispatcherTestAction2</result>
			<!-- 重定向到Action -->
			<result name="redirectAction" type="redirectAction">redirectTestAction2</result>
		</action>
		
		<action name="*TestAction2" class="action.TestAction2" method="{1}">
			<result name="dispatcher" type="dispatcher">/success.jsp</result>
			<result name="redirect" type="redirect">/success.jsp?remark=${remark}</result>
		</action>
		
		<action name="dynamicAction" class="action.DynamicAction">
			<result>${forward}</result>
		</action>
	
	</package>
</struts>    



<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
	
	<constant name="struts.i18n.encoding" value="utf-8"></constant>

	<include file="user.xml"></include>
	<include file="test.xml"></include>
</struts>    



package action;

import com.opensymphony.xwork2.ActionSupport;

public class DynamicAction extends ActionSupport {
	
	private String forward;
	
	public String test(){
		
		return SUCCESS;
	}

	public String getForward() {
		return "/"+forward;
	}

	public void setForward(String forward) {
		this.forward = forward;
	}
	
}



package action;

import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.apache.struts2.util.ServletContextAware;

import com.opensymphony.xwork2.ActionSupport;

public class TestAction1 extends ActionSupport implements ServletRequestAware,
		ServletResponseAware, SessionAware, ServletContextAware {

	private HttpServletRequest request;
	private HttpServletResponse response;
	private Map<String, Object> session;
	private ServletContext application;
	private HttpSession session2;

	private String name;
	private int age;
	private String remark;

	public String dispatcher() {

		remark = "转发到指定jsp";
		System.out.println("name=[" + name + "]");
		System.out.println("age=[" + age + "]");
		System.out.println("remark=[" + remark + "]");
		return "dispatcher";
	}

	public String redirect() {

		remark = "重定向到指定jsp";

		System.out.println("name=[" + name + "]");
		System.out.println("age=[" + age + "]");
		System.out.println("remark=[" + remark + "]");

		request.setAttribute("name", name);
		request.setAttribute("age", age);
		request.setAttribute("remark", remark);

		session2 = request.getSession();
		session2.setAttribute("name", name);
		session2.setAttribute("age", age);
		session2.setAttribute("remark", remark);

		/*
		 * session.put("name", name); session.put("age", age);
		 * session.put("remark", remark);
		 */

		return "redirect";
	}

	public String chain() {
		remark = "还在TestAction1";
		return "chain";
	}

	public String redirectAct() {
		remark = "还在TestAction1";
		return "redirectAction";
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	public void setServletContext(ServletContext application) {
		this.application = application;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

}




package action;

import java.io.UnsupportedEncodingException;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.apache.struts2.util.ServletContextAware;

import com.opensymphony.xwork2.ActionSupport;

public class TestAction2 extends ActionSupport implements ServletRequestAware,
		ServletResponseAware, SessionAware, ServletContextAware {
	private HttpServletRequest request;
	private HttpServletResponse response;
	private Map<String, Object> session;
	private ServletContext application;

	private String remark;
	private String chain;

	public String dispatcher() {
		System.out.println("TestAction2.dispatcher()");
		System.out.println("remark=[" + remark + "]");
		remark = "转发到Action";
		chain = "chain到此一游";
		return "dispatcher";
	}

	public String redirect() {
		remark = "重定向Action";
		try {
			remark = java.net.URLEncoder.encode(remark, "utf-8");
			// remark = java.net.URLEncoder.encode(remark, "utf-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "redirect";
	}

	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	public void setServletContext(ServletContext application) {
		this.application = application;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getChain() {
		return chain;
	}

	public void setChain(String chain) {
		this.chain = chain;
	}

}




package action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.apache.struts2.util.ServletContextAware;

import com.opensymphony.xwork2.ActionSupport;

import entity.Cat;
import entity.User;

public class UserAction extends ActionSupport implements ServletRequestAware,
		ServletResponseAware, SessionAware, ServletContextAware {

	private HttpServletRequest request;
	private HttpServletResponse response;
	private Map<String, Object> session;
	private ServletContext application;

	private User user;
	private String title;

	private List<Cat> cats = new ArrayList<Cat>();
	private Map<String, Cat> catMap = new HashMap<String, Cat>();

	public String login() {

		Cat m0 = new Cat("m0", "SSS", 20);
		Cat m1 = new Cat("m1", "AAA", 20);
		Cat m2 = new Cat("m2", "BBB", 20);

		Cat c0 = new Cat();
		c0.setName("c0");
		c0.setType("SSS");
		c0.setAge(10);
		c0.setMother(m0);

		Cat c01 = new Cat();
		c01.setName("c01");
		c01.setType("SSS");
		c01.setAge(5);
		c01.setMother(c0);

		Cat c02 = new Cat();
		c02.setName("c02");
		c02.setType("SSS");
		c02.setAge(6);
		c02.setMother(c0);

		Cat c03 = new Cat();
		c03.setName("c03");
		c03.setType("SSS");
		c03.setAge(7);
		c03.setMother(c0);

		c0.getChildren().add(c01);
		c0.getChildren().add(c02);
		c0.getChildren().add(c03);

		Cat c1 = new Cat();
		c1.setName("c1");
		c1.setType("AAA");
		c1.setAge(16);
		c1.setMother(m1);

		Cat c11 = new Cat();
		c11.setName("c11");
		c11.setType("AAA");
		c11.setAge(11);
		c11.setMother(c1);

		Cat c12 = new Cat();
		c12.setName("c12");
		c12.setType("AAA");
		c12.setAge(13);
		c12.setMother(c1);

		Cat c13 = new Cat();
		c13.setName("c13");
		c13.setType("AAA");
		c13.setAge(7);
		c13.setMother(c1);

		c1.getChildren().add(c11);
		c1.getChildren().add(c12);
		c1.getChildren().add(c13);

		Cat c2 = new Cat();
		c2.setName("c2");
		c2.setType("BBB");
		c2.setAge(19);
		c2.setMother(m2);

		Cat c21 = new Cat();
		c21.setName("c21");
		c21.setType("BBB");
		c21.setAge(15);
		c21.setMother(c2);

		Cat c22 = new Cat();
		c22.setName("c22");
		c22.setType("BBB");
		c22.setAge(4);
		c22.setMother(c2);

		Cat c23 = new Cat();
		c23.setName("c23");
		c23.setType("BBB");
		c23.setAge(16);
		c23.setMother(c2);

		c2.getChildren().add(c21);
		c2.getChildren().add(c22);
		c2.getChildren().add(c23);

		cats.add(c0);
		cats.add(c1);
		cats.add(c2);

		catMap.put("c0", c0);
		catMap.put("c1", c1);
		catMap.put("c2", c2);

		title = "登录成功";
		return "ognl";
	}

	public double sum(double a, double b) {
		return a * b;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public List<Cat> getCats() {
		return cats;
	}

	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	public void setServletContext(ServletContext application) {
		this.application = application;
	}

	public Map<String, Cat> getCatMap() {
		return catMap;
	}

}



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC 
  		"-//OpenSymphony Group//XWork Validator 1.0.2//EN" 
  		"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
  		
 <validators>
 	<field name="user.username">
 		<field-validator type="requiredstring">
 			<param name="trim">true</param>
 			<message>请输入用户名</message>
 		</field-validator>
 	</field>
 	
 	<field name="user.username">
 		<field-validator type="requiredstring">
 			<param name="trim">true</param>
 			<message>请输入用户密码</message>
 		</field-validator>
 	</field>
 </validators>
分享到:
评论

相关推荐

    struts2中异常处理(demo)

    Struts2是一个非常流行的Java Web框架,用于构建和维护可扩展且易于管理的企业级应用程序。...结合提供的压缩包文件"struts2_003",可能包含了示例代码或者项目结构,帮助读者理解并实践Struts2的异常处理机制。

    轻量级Java_EE企业应用实战_Struts_2+Spring_3+Hibernate整合开发_第3版_mk.zip.003

    轻量级Java_EE企业应用实战_Struts_2+Spring_3+Hibernate整合开发_第3版_mk.zip.003

    马剑威Struts2框架视频教程(27集)

    资源名称:马剑威Struts2框架视频教程(27集) ... 【】兄弟连_马剑威_003_Struts2_Action(1) 【】兄弟连_马剑威_003_Struts2_Actio 资源太大,传百度网盘了,链接在附件中,有需要的同学自取。

    Struts2之异常处理案例struts003

    Struts2是一个非常流行的Java Web框架,用于构建和维护可扩展且易于管理的企业级应用程序。在Struts2中,异常处理是一项重要的功能,它确保在应用程序遇到错误时能够优雅地处理,提供友好的用户反馈,并保持系统稳定...

    Struts2ToJson003.zip

    本案例"Struts2ToJson003.zip"应该是提供了如何在Struts2中生成并返回JSON数据的具体示例。 首先,要让Struts2支持JSON,我们需要在项目的类路径下添加Struts2的JSON插件库。这个插件通常包含在struts2-core的jar...

    STRUTS2类型转换

    Struts2是一个流行的Java web开发框架,其核心是Action,而类型转换是Struts2处理用户输入数据的一个重要环节。Struts2内置了多种类型转换,可以将HTTP请求中的字符串数据转换为各种基本类型和复杂类型,如日期、...

    关于Apache Struts 2软件存在高危漏洞的紧急通报003

    ### 关于Apache Struts 2软件存在高危漏洞的紧急通报003 #### 漏洞概述 根据温州市网络与信息安全信息通报中心发布的紧急通报(2017年第3期),Apache Struts 2软件中存在一个远程命令执行高危漏洞。此漏洞被正式...

    Java Web技术整合应用与项目实战 JSP+Servlet+Struts2+Hibernate+Spring3_13336769.zip.003

    Java Web技术整合应用与项目实战 JSP+Servlet+Struts2+Hibernate+Spring3_13336769.zip.003 Java Web技术整合应用与项目实战 JSP+Servlet+Struts2+Hibernate+Spring3_13336769.zip.003

    Struts 2权威指南完整版003

    Struts 2权威指南--基于WebWork核心的MVC开发

    struts2漏洞分析

    Struts2是一个流行的Java Web开发框架,它提供了一种模型-视图-控制器(MVC)架构,方便开发者构建动态Web应用。然而,Struts2框架在过去曾出现过多个安全漏洞,其中S2-022是针对S2-021的一个补充,暴露了框架在处理...

    Struts2-Scan:Struts2全漏洞扫描利用工具

    Struts2-ScanStruts2漏洞利用扫描工具,基于互联网上已经公开的Structs2高危漏洞exp的扫描利用工具,目前支持的漏洞如下: S2-001, S2-003, S2-005, S2-007, S2-008, S2-009, S2-012, S2-013, S2-015, S2-016, S2-019...

    Struts2&&Velocity

    在"Velocity003"这个压缩包中,可能包含了一些关于如何在Struts2项目中集成和使用Velocity模板的示例代码或教程。例如,可能有Action类的实现,展示了如何设置和返回结果对象;还有Velocity模板文件,演示了如何在...

    Struts2+Spring3+Hibernate4+Maven+EasyUI整合入门视频003

    视频教程"Struts2+Spring3+Hibernate4+Maven+EasyUI整合入门视频003"可能涵盖了以下内容: 1. Maven的配置和项目初始化:介绍如何创建Maven项目,配置pom.xml文件,添加Struts2、Spring3、Hibernate4和EasyUI的依赖...

    一篇文章搞定Struts2的类型转换

    在Web开发中,Struts2作为一个流行的MVC框架,负责处理用户请求并将其转化为可操作的数据。然而,由于HTTP协议的特性,所有从客户端提交的数据都是字符串形式。因此,为了将这些字符串转换为Java中的各种数据类型,...

    struts 当当王

    7. **拦截器(Interceptor)**:Struts2引入了拦截器,可以实现如登录检查、日志记录、性能监控等通用功能,提高代码复用性和可维护性。 8. **Tiles框架集成**:为了方便页面布局,可能会使用Tiles框架,它允许开发者...

    Struts2-ScanEN:这是来自的翻译项目

    Struts2漏洞利用扫描工具基于Internet上已发布的Structs2高风险漏洞exp的扫描利用工具,当前支持的漏洞如下:S2-001,S2-003,S2-005,S2-007, S2-008,S2-009,S2-012,S2-013,S2-015,S2-016,S2-019,S2-029,...

    Java_Web整合开发 王者归来003

    - **Struts2**:Struts2是另一个流行的MVC框架,它具有拦截器机制、国际化支持等特点。 #### 五、数据库集成 在Java Web开发中,通常需要与数据库进行交互。这涉及到使用JDBC(Java Database Connectivity)或其他...

    SSH(三)视频

    Struts2+Hibernate3.2+Spring2.0整合续三的视频,对java初学者不错!

    hibernate课程源码.

    1. **003_HibernateSession**: 这部分涵盖了Hibernate的核心组件——Session。Session是Hibernate中与数据库进行交互的主要接口,用于保存、更新、删除和检索持久化对象。学习这个模块,你会理解如何创建Session,...

Global site tag (gtag.js) - Google Analytics