【struts2】struts2的全局结果处理和依赖注入案例
来源:互联网 发布:apache视频教程 编辑:程序博客网 时间:2024/06/05 09:20
web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><!-- 添加启动struts2MVC框架的过滤器 --><filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class></filter><filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern></filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app>
index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%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><div align="center"><h3>登陆操作</h3><form action="${pageContext.request.contextPath }/csdn/login.action" method="post">用户名:<input type="text" name="name" /><br />密码:<input type="password" name="pass" /><br /><input type="submit" value="登陆"></form></div></body></html>
sc.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%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 'sc.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> <div align="center"> <h3>登陆成功!</h3> </div> </body></html>
LoginAction.java
package www.csdn.struts_action.action;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport {/** * */private static final long serialVersionUID = 1L;// 接受客户端的值private String name;private String pass;private String upload;public String getName() {return name;}// 注入public void setName(String name) {this.name = name;}public String getPass() {return pass;}public void setPass(String pass) {this.pass = pass;}public String getUpload() {return upload;}public void setUpload(String upload) {this.upload = upload;}public String login() {System.out.println("处理业务....."+name+"--"+pass+"---"+upload);return SUCCESS;}}
struts.xml
<?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><!--${pageContext.request.contextPath }/csdn/login.actionurl:http://localhost:8080/struts_action/csdn/login.actionstruts-default 包名--><package name="user" namespace="/csdn" extends="struts-default"><!-- 全局的结果集 --><global-results><result name="success" type="dispatcher">/sc.jsp</result></global-results><!--<default-class-ref class="com.opensymphony.xwork2.ActionSupport" />Method=execute--><action name="login" class="www.csdn.struts_action.action.LoginAction"method="login"><param name="upload">/images</param><!--name="success" <result-type name="dispatcher"class="org.apache.struts2.dispatcher.ServletDispatcherResult"default="true"/>--><result name="success" type="dispatcher">/index.jsp</result></action></package></struts>
当没有
<result name="success" type="dispatcher">/index.jsp</result>跳转到sc页面,
添加上
<result name="success" type="dispatcher">/index.jsp</result>则跳转到index页面
- 【struts2】struts2的全局结果处理和依赖注入案例
- struts2--全局结果集和异常处理配置
- struts2-java框架-依赖注入案例3
- Struts2全局异常 全局结果的配置
- struts2全局结果
- Struts2 全局结果集
- Struts2中的全局结果
- 全局结果集,带参数的结果集和动态结果集(struts2)
- Struts2的Global Results全局结果集
- struts2异常处理,global-results定义全局结果处理
- struts2异常处理,global-results定义全局结果处理
- struts2的结果处理方式
- Struts2对依赖注入的支持
- struts2中action属性的依赖注入
- struts2全局结果与异常处理(五)
- Struts2全局结果,action链及动态结果的应用
- struts2 result全局结果集
- Struts2中的全局结果集
- linux + apache 2.4.4 + php配置
- qt 中文乱码
- C#计算两个字符串的相似度
- 鼓舞自己的士气
- CSDN开博卷首语
- 【struts2】struts2的全局结果处理和依赖注入案例
- 认识设计模式中的每个模式
- 怎样培养阅读习惯
- omap移植systemtap
- pat1016 Phone Bills
- python字符串处理函数
- FastDb 简单编码运用
- 经典算法总结记忆
- Excel单元格内容变化时,自动添加系统时间批注(亲自实践)