Struts2_19_DynamicResult
来源:互联网 发布:几米软件 编辑:程序博客网 时间:2024/06/06 06:55
动态结果集:
action中的result页面是动态获取的,即通过属性的改变,虽然Result name是一样,但是结果页面不一样。
重点:
<?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>
<constant name="struts.devMode" value="true" />
<constant name="struts.i18n.encoding" value="GBK"></constant>
<package name="user" namespace="/user" extends="struts-default">
<action name="user" class="com.awei.struts2.action.UserAction">
<result >${r}</result>
</action>
</package>
<!-- Add packages here -->
</struts>
这个r是什么呢?
来看com.awei.struts2.action.UserAction的定义:
package com.awei.struts2.action;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport{
private String type;
private String r;
public String getR() {
return r;
}
public void setR(String r) {
this.r = r;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String execute(){
if("1".equals(type)){
r="/index1.jsp";
}else if("2".equals(type)){
r="/index2.jsp";
}
return SUCCESS;
}
}
Action会把所有的属性都加入到value Stack中,这样就可以通过Property Name来获得value;
${r}是OGNL表达式。
index.jsp页面的定义:
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
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>
<a href="user/user?type=1">进入界面一</a> <br>
<a href="user/user?type=2">进入界面二</a> <br>
</body>
</html>
0 0
- Struts2_19_DynamicResult
- 英雄会第四届在线编程大赛·线上初赛:带通配符的数
- android中的category
- 【Android】代码收集
- Struts2_18_GlobalResult
- MSTR管理
- Struts2_19_DynamicResult
- Cocos2d-x学习之---3.0rc版新建工程
- Struts2_20_ResultWithParameter
- 如何进行代理上网以及ccproxy设置
- UVA 11865 Stream My Contest(最小树形图、朱刘算法)
- 关于使用JSON库的时候,出现[NSCFString JSONValue]: unrecognized selector sent to instance的问题
- OTL的使用
- 游戏服务器之长连接服务器(python)(2)
- android中的broadcast action