本文共 1283 字,大约阅读时间需要 4 分钟。
在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" class="com.liyong.StructsInlayObject.StructsInlayObject" method="Scope" > <result name="scope">/WEB-INF/page/scope.jsp</result> <!-- 访问路径 http://localhost:8080/Structs2/test/Scope --> </action> 第五步:部署....转载地址:http://jedrz.baihongyu.com/