2019独角兽企业重金招聘Python工程师标准>>>

1、概述

2、resultd的name属性

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><!-- Add packages here --><constant name="struts.devMode" value="true" /><constant name="struts.enable.DynamicMethodInvocation" value="false"></constant><!-- 取名与用户模块相对应 --><!-- <package name="default" namespace="/" extends="struts-default"> --><package name="user" namespace="/user" extends="struts-default"><default-action-ref name="index"/><action name="index"><result>/index.jsp</result></action><action name="login" class="com.ljb.web.action.LoginAction"><result>/loginSuccess.jsp</result></action></package>
</struts>

login.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><form action="user/login" method="post">用户名:<input type="text" name="userName"/><br/>密码:<input type="password" name="password"/><br/>年龄:<input type="text" name="age"/><br/><input type="submit" value="提交"/>&nbsp;&nbsp;<input type="reset" value="重置"/></form>
</body>
</html>

注:路径(user/login)

小结:

3、result的type属性

<?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><!-- Add packages here --><constant name="struts.devMode" value="true" /><constant name="struts.enable.DynamicMethodInvocation" value="false"></constant><package name="user" namespace="/user" extends="struts-default"><default-action-ref name="index"/><action name="index"><result>/index.jsp</result></action><action name="login" class="com.ljb.web.action.LoginAction" method="login"><result name="success">/loginSuccess.jsp</result><result name="input">/login.jsp</result></action></package>
</struts>
package com.ljb.web.action;
import com.opensymphony.xwork2.ActionSupport;
/*** 第一种传递参数方法(设置私有属性,设置set与get方法)* @author Administrator**/
public class LoginAction extends ActionSupport {private String userName;private String password;private int age;public int getAge() {return age;}public void setAge(int age) {this.age = age;}public String getUserName() {return userName;}public void setUserName(String userName) {this.userName = userName;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}@Overridepublic String execute() throws Exception {// TODO Auto-generated method stubreturn SUCCESS;}public String login () {if (userName.equals("admin")&&password.equals("ok")) {return SUCCESS;} else {return INPUT;}}
}

小结:

 4、全局结果

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><!-- Add packages here --><constant name="struts.devMode" value="true" /><package name="house" namespace="/house" extends="struts-default"><global-results><result name="error">/error.jsp</result></global-results><!-- <action name="house_add" class="com.ljb.web.action.HouseAction" method="add"><result>/house_add_success.jsp</result></action><action name="house_update" class="com.ljb.web.action.HouseAction" method="update"><result>/house_update_success.jsp</result></action> --><action name="house_*" class="com.ljb.web.action.HouseAction" method="{1}"><result>/house_{1}_success.jsp</result></action></package>
</struts>

house_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><form action="house/house_add" method="post"><input type="submit" value="添加房屋信息"/></form>
</body>
</html>

HouseAction类:

package com.ljb.web.action;
import com.opensymphony.xwork2.ActionSupport;
public class HouseAction extends ActionSupport {/*** 添加房屋信息* @return*/public String add () {System.out.println("处理添加房屋信息。");// 模拟添加房屋信息异常try {if (1==1) {throw new Exception();}} catch (Exception e) {return ERROR;}return SUCCESS;}/*** 修改房屋信息* @return*/public String update () {System.out.println("处理修改房屋信息。");return SUCCESS;}@Overridepublic String execute() throws Exception {// TODO Auto-generated method stubreturn SUCCESS;}
}

 5、动态结果

login.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><form action="user/login" method="post">用户名:<input type="text" name="userName"/><br/>密码:<input type="password" name="password"/><br/>年龄:<input type="text" name="age"/><br/><input type="submit" value="提交"/>&nbsp;&nbsp;<input type="reset" value="重置"/></form>
</body>
</html>

commonSuccess.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>普通用户页面</h1>
</body>
</html>

adminSuccess.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>管理员页面</h1>
</body>
</html>

CommonAction:

package com.ljb.web.action;
import com.opensymphony.xwork2.ActionSupport;
public class CommonAction extends ActionSupport {@Overridepublic String execute() throws Exception {// TODO Auto-generated method stubreturn SUCCESS;}
}

AdminAction:

package com.ljb.web.action;
import com.opensymphony.xwork2.ActionSupport;
public class AdminAction extends ActionSupport {@Overridepublic String execute() throws Exception {// TODO Auto-generated method stubreturn SUCCESS;}
}

LoginAction:

package com.ljb.web.action;
import com.opensymphony.xwork2.ActionSupport;
/*** 第一种传递参数方法(设置私有属性,设置set与get方法)* @author Administrator**/
public class LoginAction extends ActionSupport {// 定义下一个需要跳转的action对应的字符串名称private String nextAction;public String getNextAction() {return nextAction;}public void setNextAction(String nextAction) {this.nextAction = nextAction;}private String userName;private String password;private int age;public int getAge() {return age;}public void setAge(int age) {this.age = age;}public String getUserName() {return userName;}public void setUserName(String userName) {this.userName = userName;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}@Overridepublic String execute() throws Exception {// TODO Auto-generated method stubreturn SUCCESS;}public String login () {if (userName.equals("admin")&&password.equals("admin")) {nextAction = "admin";return SUCCESS;} else if (userName.equals("common") && password.equals("common")) {nextAction = "common";return SUCCESS;} else {return INPUT;}}
}

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><!-- Add packages here --><constant name="struts.devMode" value="true" /><package name="user" namespace="/user" extends="struts-default"><default-action-ref name="index"/><action name="index"><result>/index.jsp</result></action><action name="login" class="com.ljb.web.action.LoginAction" method="login"><result name="success" type="redirectAction">${nextAction}</result><result name="input">/login.jsp</result></action><action name="common" class="com.ljb.web.action.CommonAction"><result>/commonSuccess.jsp</result></action><action name="admin" class="com.ljb.web.action.AdminAction"><result>/adminSuccess.jsp</result></action></package></struts>

 6、小结

转载于:https://my.oschina.net/u/2320342/blog/414145

使用result配置结果视图相关推荐

  1. 【Struts2学习笔记(1)】Struts2中Action名称的搜索顺序和多个Action共享一个视图--全局result配置...

    一.Action名称的搜索顺序 1.获得请求路径的URI,比如url是:http://server/struts2/path1/path2/path3/test.action 2.首先寻找namesp ...

  2. springmvc配置thymeleaf视图解析器

    引入thymeleaf的依赖 <dependency><groupId>org.thymeleaf</groupId><artifactId>thyme ...

  3. 15.Result配置详解

    转自:https://wenku.baidu.com/view/84fa86ae360cba1aa911da02.html 说明:在前面的许多案例中我们所用到的Action基本都继承自ActionSu ...

  4. 基于XML配置的Spring MVC(所需jar包,web.xml配置,处理器配置,视图解析器配置)

    1.添加jar 2.web.xml配置 <?xml version="1.0" encoding="UTF-8"?> <web-app ver ...

  5. 深入详解Struts2——struts.xml配置之Result配置详解

    一个result代表了一个可能的输出,当Action类的方法执行完成时,它返回一个字符串的结果码,框架根据这个结果码选择对应的result,向用户输出. result元素有两个属性 name:指定re ...

  6. 【JetPack】为现有 Android 项目配置视图绑定 ( ViewBinding ) 模块 ( 视图绑定不影响传统布局操作 | 视图绑定类关联 Activity | 视图绑定类本质 )

    文章目录 I . 为现有项目配置 视图绑定 ( ViewBinding ) 应用 II . 视图绑定 ( ViewBinding ) 定制 III . 视图绑定 ( ViewBinding ) 对于正 ...

  7. Struts2中 Result类型配置详解

    一个result代表了一个可能的输出.当Action类的方法执行完成时,它返回一个字符串类型的结果码,框架根据这个结果码选择对应的result,向用户输出. 在com.opensymphony.xwo ...

  8. Python基础之 Django视图和 URL 配置

    通过上节文章中命令创建项目,然后创建视图文件,配置url,然后启动项目. 1进入相应目录,创建项目命令如下: C:\Windows\system32>f: F:\>cd F:\python ...

  9. 视图解析器中配置前缀和后缀---SpringMVC学习笔记(五)

    springmvc.xml中配置的视图解析器中增加jsp路径的前缀和后缀配置: <!-- 配置视图解析器 --><bean class="org.springframewo ...

  10. freemarker视图解析配置

    这里写目录标题 maven依赖 配置文件 多视图解析配置 maven依赖 <dependency><groupId>org.freemarker</groupId> ...

最新文章

  1. 【Unity】5.1 3D坐标系基础知识
  2. VC实现基于Office 2007 MODI 12.0实现图形文字识别(OCR)的程序
  3. 数据分析实例(股票分析实例)
  4. Spring 属性配置
  5. android学习日记16--GridView(网格视图)
  6. 零分钟即可在容器开发套件(CDK)上实现云运营
  7. 【WebRTC---源码篇】(二)PeerConnectionFactory
  8. java pojo 转 map_JSON和JAVA的POJO的相互转换
  9. 数据3分钟丨Oracle Database 21c终于发布而22c可能直接跳过;2021 OceanBase数据库大赛开启。...
  10. DocumentHelper解析xml文件
  11. 吴军信息论40讲_吴军:有时候成功比失败更糟糕!顺势而为还是走弯路,就看一件事...
  12. 【WPF】 免费图表控件的比较 (OxyPlot,LiveChart,ScottPlot,MsChart)
  13. 基于java+jsp的户籍管理系统
  14. uc手机浏览器 手机模拟_在PC上测试移动端网站和模拟手机浏览器的5大方法
  15. 在python中查询excel内容
  16. thinkphp6获取字符串中的中文首字母
  17. Pygame详解(七):key 模块
  18. 使用李跳跳·自动关闭运动校园广告
  19. Python字符串连接
  20. android录音波浪动画_Android 自定义 view 实现波浪动画进度条

热门文章

  1. Vector、ArrayList和List的异同
  2. pandas 调整列的顺序
  3. caffe 将数据(非图像和图像)转成lmdb格式的数据
  4. 扫地机器人湿地_黑五好价 美亚直邮 iRobot Braava 380t 拖地机器人
  5. mysql设置主键可视化_mysql怎么设置主键自
  6. 人工智能python3+tensorflow人脸识别_Tensorflow+opencv2实现人脸识别
  7. git 合并其他分支代码到自己的分支
  8. Kotlin — 适用于原生
  9. Futter基础第9篇: 实现页面跳转、跳转传值(命名路由、命名路由传值)
  10. rk3399_android7.1调试USB接口的TP记录