Struts2 Result配置 和 Struts2异常配置
2015-06-11 00:00
507 查看
<%@ 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> <title>Struts2 HelloWorld示例</title> </head> <body> <h3>Struts2 HelloWorld示例</h3> <hr> <form action="login.action" method="post"> 用户名:<input type="text" name="userName"><br> 密 码:<input type="password" name="password"><br> <input type="submit" value="登录"> <input type="reset" value="重置"> </form> </body> </html>
<?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"> <!-- step3:struct2 的核心配置文件 --> <!-- step4:添加项目所需的文件 --> <struts> <!-- 请求消息的编码方式 默认的编码为UTF-8 --> <constant name="struts.i18n.encoding" value="UTF-8"></constant> <!-- 指定被struts2处理的请求后缀类型。多个用逗号隔开 --> <constant name="struts.action.extension" value="action,do,go,zhangsan,lisi"></constant> <!-- 默认值为false(生产环境下使用),开发阶段最好打开 --> <constant name="struts.configuration.xml.reload" value="true"></constant> <!-- 是否使用struts的开发模式。开发模式会有更多的调试信息。默认值为false(生产环境下使用),开发阶段最好打开 --> <constant name="struts.devMode" value="false"></constant> <!-- 启用Action的name是否支持斜线(/) --> <constant name="struts.enable.SlashesInActionNames" value="true"></constant> <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant> <package name="default" namespace="/" extends="struts-default"> <!-- 配置全局的result--> <global-results> <result name="success">/success.jsp</result> </global-results> <!-- 全局异常 --> <global-exception-mappings> <exception-mapping result="success" exception="java.lang.Exception"></exception-mapping> </global-exception-mappings> <action name="login" class="derun.action.LoginAction"> <result name="fail">/fail.jsp</result> </action> </package> </struts>
package derun.action; import com.opensymphony.xwork2.ActionContext; public class LoginAction { private String userName; private String password; private int id; public String execute(){ if(userName.equals("admire")&&password.equals("admire")){ System.out.println(10/0); return "success"; }else{ return "fail"; } } public String edit(){ ActionContext.getContext().put("id", 10); return "edit"; } public String update(){ System.out.println("id的值是:---->"+id); return "success"; } public void setUserName(String userName) { System.out.println("调用set方法给userName赋值"); this.userName = userName; } public void setPassword(String password) { System.out.println("调用set方法给password赋值"); this.password = password; } public void setId(int id) { this.id = id; } }
<%@ 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>登录成功</title> </head> <body> <h3>登录成功</h3> <s:property value="exception.message"/><br> <s:property value="exceptionStack"/> </body> </html>
<%@ 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>登录失败</title> </head> <body> <h3>登录失败</h3> </body> </html>
相关文章推荐
- eclipse中运行spark机器学习代码
- Eclipse NDK安装流程详解
- 【Java基础】——java基本语法(2)
- Java--使用多线程下载,断点续传技术原理(RandomAccessFile)
- 2015061006 - java Tools
- 2015第24周三Spring事务3
- Eclipse将引用了第三方jar包的Java项目打包成jar文件
- Struts 2 知识笔记
- springMVC之一
- JAVABean的应用
- Spring security实现指定用户session过期
- Java设计模式——Mediator(中介者)模式
- SPRING技术内幕-笔记(七)WEB环境中的springMVC
- java list 取交集,差集
- 直接选择排序 Java
- Java的一些父类(一)
- Spring和Struts2整合
- Eclipse上GIT插件EGIT使用手册
- MyEclipse 2014 有用的几个快捷键
- JAVA并发编程——守护线程(Daemon Thread)