4.访问web元素[1],容器获取
来源:互联网 发布:大数据在电商中的应用 编辑:程序博客网 时间:2024/04/30 23:53
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>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<package name="login" namespace="/login" extends="struts-default">
<action name="login*"
class="com.example.struts.action.LoginAction{1}">
<result >
/success.jsp
</result>
</action>
</package>
</struts>
<!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.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<package name="login" namespace="/login" extends="struts-default">
<action name="login*"
class="com.example.struts.action.LoginAction{1}">
<result >
/success.jsp
</result>
</action>
</package>
</struts>
LoginAction1
package com.example.struts.action;
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction1 extends ActionSupport{
private Map request; //类型是Map=【key】加【value】的组合
private Map session;
private Map application;
public LoginAction1(){ //必须加上public,否则在action调用该类时不可以执行该构造函数
request=(Map)ActionContext.getContext().get("request");
//ActionContext.getContext(),获取当前环境
session= ActionContext.getContext().getSession();
application= ActionContext.getContext().getApplication();
}
public String execute() {
request.put("r1", "r1"); //(key,value)
session.put("s1", "s1");
application.put("a1","a1");
return SUCCESS;
}
}
login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>登陆页面</title>
</head>
<body>
<form name="f" action="" method="post">
用户名: <input type="text" name="name"/>
密码:<input type="text" name="password"/>
<br/>
<input type="button" value="submit1" onClick="javascript:document.f.action='login/login1';document.f.submit();"/>
<input type="button" value="submit2" onClick="javascript:document.f.action='login/login2';document.f.submit();"/>
<input type="button" value="submit3" onClick="javascript:document.f.action='login/login3';document.f.submit();"/>
<input type="button" value="submit4" onClick="javascript:document.f.action='login/login4';document.f.submit();"/>
// onClick="指定传入action"
</form>
</body>
</html>
success.jsp
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>登陆成功</title>
</head>
<body>
<s:property value="#request.r1"/>|<%=request.getAttribute("r1") %><br>
<s:property value="#session.s1"/>|<%=session.getAttribute("s1") %><br>
<s:property value="#application.a1"/>|<%=application.getAttribute("a1") %><br>
//#application.a1意思是
//Stack Context
//These items are available using the #key notation//必须加#才可以访问
Stack Context的内容
//web也可以访问,原因是把struts的内容也复制到了web中。
也就是<%=request.getAttribute("r1") %>也有值。
<s:debug></s:debug>
</body>
</html>
------------------------------------------------------------------------------------------------------------
运行结果:
-----------------------------------
原来说明:
0 0
- 4.访问web元素[1],容器获取
- Struts2_10_struts访问web元素1依赖容器
- Struts2获取Web容器资源的方式 访问request,session
- Struts2访问web元素 获取request,session,application
- 顺序容器5 访问元素
- 迭代器访问容器中的元素
- C++ 顺序容器访问元素
- 访问web元素
- struts2访问web元素
- Struts2_访问Web元素
- Struts2访问 web 元素
- Struts2访问Web元素
- struts2访问web元素
- struts2访问web元素
- Struts2访问Web元素
- struts2访问web元素
- Struts2访问web元素
- Struts2访问web元素
- 杭电题目分类
- Ruby模块Module
- android wifi
- Nginx搭建反向代理服务器
- python中文件OS模块访问函数
- 4.访问web元素[1],容器获取
- Andorid内存检测工具:LeakCanary
- 如何让apache支持.htaccess 解决Internal Server Error The server …错误
- 性能调优工具:JDK 命令行工具之jstatd
- fushionchart的Pie3D的具体使用方法
- java通过JDBC驱动连接操作hive实例
- 对Pedestrian Detection aided by Deep Learning Semantic Tasks的小结
- iOS开发UI篇—Quartz2D使用(绘制基本图形)
- Handler post()等在子线程中更新主线程的UI的方法使用小汇