<?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>
<package name="user" namespace="/user" extends="struts-default">
<global-results>
<result name="success">/success.jsp</result>
</global-results>
<action name="loginAction" class="action.LoginAction">
<result name="error">/index.jsp</result>
</action>
<action name="testAction" class="action.TestAction">
</action>
<action name="testAction1" class="action.TestAction1">
</action>
<action name="testAction2" class="action.TestAction2">
</action>
<action name="testAction3" class="action.TestAction3">
</action>
<action name="testAction4" class="action.TestAction4">
</action>
</package>
</struts>
package action;
import com.opensymphony.xwork2.ActionSupport;
import entity.User;
public class LoginAction extends ActionSupport {
private User user;
public String login() {
String r = "success";
if (null == user.getUserName() || "".equals(user.getUserName())) {
addFieldError("error_name", "username is error!");
r = "error";
} else if (null == user.getPassword() || "".equals(user.getPassword())) {
addFieldError("error_pwd", "password is error!");
r = "error";
}
return r;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
package action;
public class TestAction {
public String test(){
System.out.println("test");
return null;
}
}
package action;
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class TestAction1 extends ActionSupport {
private Map<String, Object> request;
private Map<String, Object> session;
private Map<String, Object> application;
@SuppressWarnings("unchecked")
public String test() {
request = (Map<String, Object>) ActionContext.getContext().get(
"request");
session = ActionContext.getContext().getSession();
application = ActionContext.getContext().getApplication();
request.put("r1", "r1");
session.put("s1", "s1");
application.put("a1", "a1");
return SUCCESS;
}
}
package action;
import java.util.Map;
import org.apache.struts2.interceptor.ApplicationAware;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;
import sun.org.mozilla.javascript.internal.ContextAction;
import com.opensymphony.xwork2.ActionSupport;
public class TestAction2 extends ActionSupport implements RequestAware,SessionAware,ApplicationAware {
private Map<String,Object> request;
private Map<String,Object> session;
private Map<String,Object> application;
public String test(){
request.put("r1", "r11");
session.put("s1", "s11");
application.put("a1", "a11");
return SUCCESS;
}
public void setRequest(Map<String, Object> request) {
this.request = request;
}
public void setSession(Map<String, Object> session) {
this.session = session;
}
public void setApplication(Map<String, Object> application) {
this.application = application;
}
}
package action;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class TestAction3 extends ActionSupport {
private HttpServletRequest request;
private HttpServletResponse response;
private HttpSession session;
private ServletContext application;
public String test() {
request = ServletActionContext.getRequest();
response = ServletActionContext.getResponse();
session = request.getSession();
application = ServletActionContext.getServletContext();
request.setAttribute("r1", "r111");
session.setAttribute("s1", "s111");
application.setAttribute("a1", "a111");
return SUCCESS;
}
}
package action;
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.util.ServletContextAware;
import com.opensymphony.xwork2.ActionSupport;
public class TestAction4 extends ActionSupport implements ServletRequestAware,
ServletResponseAware, ServletContextAware {
private HttpServletRequest request;
private HttpServletResponse response;
private HttpSession session;
private ServletContext application;
public String test() {
session = request.getSession();
request.setAttribute("r1", "r1111");
session.setAttribute("s1", "s1111");
application.setAttribute("a1", "a1111");
return SUCCESS;
}
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
public void setServletResponse(HttpServletResponse response) {
this.response = response;
}
public void setServletContext(ServletContext application) {
this.application = application;
}
}
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<form action="user/loginAction!login" method="post">
username:<input type="text" name="user.userName"/><s:fielderror fieldName="error_name"></s:fielderror><br/>
password:<input type="password" name="user.password" /><s:fielderror fieldName="error_pwd"></s:fielderror> <br/>
<input type="submit" value="登录"/>
<s:debug></s:debug>
</form>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'success.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<font color="red">${user.userName }</font>登录成功....
<br />
<font color="red"><s:property value="user.userName" />
</font>登录成功....
<br />
<font color="red"><s:property value="#request.user.userName" />
</font>登录成功....
<br />
<s:property value="#request.r1" />
<br />
<s:property value="#session.s1" />
<br />
<s:property value="#application.a1" />
<br />
<s:debug></s:debug>
</body>
</html>
分享到:
相关推荐
轻量级Java_EE企业应用实战_Struts_2+Spring_3+Hibernate整合开发_第3版_mk.zip.002
总的来说,Struts2.3-002.rar提供的资料对于学习和使用Struts2框架,尤其是2.3.1.1这个特定版本,具有很高的参考价值。通过学习和实践,开发者可以更好地利用Struts2构建稳定、高效的Web应用程序。
【】兄弟连_马剑威_002_HelloStruts2入门 【】兄弟连_马剑威_003_Struts2_Action(1) 【】兄弟连_马剑威_003_Struts2_Actio 资源太大,传百度网盘了,链接在附件中,有需要的同学自取。
Struts2-002是一个针对Java开发的Web应用程序中的XSS(跨站脚本)漏洞,主要影响Apache Struts框架的特定版本。该漏洞出现在使用和标签时,特别是当这些标签的`includeParams`属性设置为`all`的情况下。受影响的...
本案例"Struts2之类型转换器的使用案例struts002"深入探讨了如何自定义类型转换器以及在实际应用中的使用。 首先,Struts2框架提供了一系列内置的类型转换器,可以自动处理基本类型和常见类型的数据转换,如String...
Struts 2练习源码 第二天002Struts 2练习源码 第二天002Struts 2练习源码 第二天002Struts 2练习源码 第二天002Struts 2练习源码 第二天002Struts 2练习源码 第二天002
Struts2、Spring2和Hibernate3是经典的Java Web开发框架组合,它们在企业级应用中广泛使用,构建了MVC(Model-View-Controller)架构的基础。这个完整的案例旨在展示如何将这三个框架集成,实现数据的增删查操作。...
01介绍struts2及struts2开发环境的搭建.zip.002
在“Struts2+Spring3+Hibernate4+Maven+EasyUI整合入门视频002”中,可能涵盖了以下内容: 1. Maven项目配置:讲解如何创建Maven项目,配置POM.xml文件,引入所需的Struts2、Spring3、Hibernate4和EasyUI的依赖。 2...
本案例主要关注的是如何将Hibernate ORM(对象关系映射)框架与Struts2 MVC(模型-视图-控制器)框架整合,同时探讨MVC分层架构在实际应用中的运用。以下是对这些知识点的详细说明: **1. Hibernate ORM框架** ...
Struts 2权威指南--基于WebWork核心的MVC开发
《Struts编程(第2版)》是一本深入讲解Struts框架的权威指南,它针对的是Java Web开发领域。Struts是Apache软件基金会旗下面向MVC(模型-视图-控制器)设计模式的Java EE应用程序框架,它极大地简化了构建基于JSP和...
2. **控制器层**:Struts框架接收到请求后,根据struts-config.xml配置找到对应的Action,执行该Action的execute方法。 3. **业务逻辑层**:在Action的execute方法中,使用Hibernate的Session查询数据库,查找匹配的...
2. **Struts配置文件**:在系统中,通常会有一个名为`struts-config.xml`的配置文件,它定义了Action类、ActionForm表单对象、数据源、结果页面映射等关键元素,是整个系统的调度中心。 3. **Action和ActionForm**...
研磨Struts2-高清-完整目录-2011年10月,分享给所有需要的人
"BBS.rar.002" 文件可能是源代码的分卷压缩包,需要所有分卷才能完整解压。这通常意味着源代码文件量较大,包含了多个模块和层次的代码。开发者可能将系统划分为不同的包和类,以遵循良好的编码规范和可维护性。 5...
SSH,全称Struts2 + Spring + Hibernate,是Java Web开发中广泛使用的一种集成框架,用于构建高效、可维护性高的企业级应用程序。它将MVC(Model-View-Controller)设计模式的三个部分进行解耦,提高了开发效率,...
在部署Java Web应用程序到Apache Tomcat服务器的过程中,经常会遇到各种各样的问题,其中一种常见的错误就是启动时出现“严重:Exception starting filters struts2”这样的异常信息。本文将详细解析这个错误的原因,...
- **Struts2**:基于MVC模式的开源框架,支持拦截器、类型转换等高级功能。 - **MVC模式**:Model-View-Controller架构模式,将应用程序逻辑划分为三部分:业务逻辑(Model)、表示层(View)和控制层(Controller)...
SSH,全称Struts2 + Spring + Hibernate,是Java Web开发中的一个流行组合,常用于构建企业级应用程序。这个“一个ssh项目分卷2”很可能是一个包含完整SSH框架的示例项目,旨在帮助开发者熟悉和练习SSH框架的使用。...