首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

访问或平添request/session/application属性

2012-09-10 
访问或添加request/session/application属性在Structs中访问或添加request/session/application属性方法:

访问或添加request/session/application属性
在Structs中访问或添加request/session/application属性方法:

代码如下:
第一步:Action
public class StructsInlayObject{
 
public String Scope()
{
ActionContext ctx = ActionContext.getContext();
ctx.getApplication().put("application","myApplication");
ctx.getSession().put("session", "mySession");
ctx.put("request", "myRequest");
return "scope";
}
}

第二步:从JSP中获得这些属性的值

scope.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'hello.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>
    Application:${applicationScope.application}<br/>
Session:${sessionScope.session}<br/>
Request:${requestScope.request}<br/>
  </body>
</html>

第三步:在stucts.xml文件中配置Actin

<action name="Scope" method="Scope" >
<result name="scope">/WEB-INF/page/scope.jsp</result>
<!-- 访问路径 http://localhost:8080/Structs2/test/Scope -->
        </action>

第五步:部署....

热点排行
Bad Request.