易截截图软件、单文件、免安装、纯绿色、仅160KB

struts2中action如何获取jsp页面参数


1. ActionContext
在Struts2开发中,除了将请求参数自动设置到Action的字段中,我们往往也需要在Action里直接获取请求(Request)或会话
(Session)的一些信息,甚至需要直接对JavaServlet
Http的请求(HttpServletRequest),响应(HttpServletResponse)操作.
我们需要在Action中取得request请求参数"username"的值:
ActionContext context = ActionContext.getContext();
Map params = context.getParameters();
String username = (String) params.get("username");
ActionContext(com.opensymphony.xwork.ActionContext)是Action执行时的上下文,上下文可以看
作是一个容器(其实我们这里的容器就是一个Map而已),它存放的是Action在执行时需要用到的对象. 一般情况,
我们的ActionContext都是通过: ActionContext context = (ActionContext)
actionContext.get();来获取的.我们再来看看这里的actionContext对象的创建:
static ThreadLocal actionContext = new ActionContextThreadLocal();
ActionContextThreadLocal是实现ThreadLocal的一个内部类.ThreadLocal可以命名为"线程局部变
量",它为每一个使用该变量的线程都提供一个变量值的副本,使每一个线程都可以独立地改变自己的副本,而不会和其它线程的副本冲突.这样,我们
ActionContext里的属性只会在对应的当前请求线程中可见,从而保证它是线程安全的.
通过ActionContext取得HttpSession: Map session = ActionContext.getContext().getSession();
2. ServletActionContext
ServletActionContext(com.opensymphony.webwork.
ServletActionContext),这个类直接继承了我们上面介绍的ActionContext,它提供了直接与Servlet相关对象访问的
功能,它可以取得的对象有:
(1)javax.servlet.http.HttpServletRequest : HTTPservlet请求对象
(2)javax.servlet.http.HttpServletResponse : HTTPservlet相应对象
(3)javax.servlet.ServletContext : Servlet上下文信息
(4)javax.servlet.ServletConfig : Servlet配置对象
(5)javax.servlet.jsp.PageContext : Http页面上下文
如何从ServletActionContext里取得Servlet的相关对象:
<1>取得HttpServletRequest对象: HttpServletRequest request = ServletActionContext. getRequest();
<2>取得HttpSession对象: HttpSession session = ServletActionContext. getRequest().getSession();
3. Serv


相关文档:

Struts2框架JSP页面传输中文乱码问题解决

Action代码
package com.zxc.action;import java.net.URLEncoder;public class XiaoZAction {
private String username; public String getUsername() { return username; }
public String execute() throws Exception{
username = URLEncoder.encode("周小川", "utf-8"); return "success"; }}

struts.x ......

JSP内置对象(9个常用的内置对象)

JSP内置对象(9个常用的内置对象)  
 1.request对象 
客户端的请求信息被封装在request对象中,通过它才能了解到客户的需求,然后做出响应。它是HttpServletRequest类的实例。 
序号 方 法 说 明 
1 object getAttribute(String name) 返回指定属性的属性值 
2 Enumeration getAttr ......

jsp页面div应用

<%@ page contentType="text/html;charset=GBK"%>
<div id="divDisable" style="display: none;width:expression(document.body.offsetWidth); height:100%; z-index: 1000; position: absolute;left: 0px; top: 0px;filter:alpha(opacity=50); background-color:White">
</div>
<div id="divWaiti ......

在JSP中用Object对象来传递值

JavaScript代码:
          //办事处抽取比例改变,更新其他数据
....function changeOfficeSampleScale(obj,flushOfficeRow){
 var row=obj.parentNode.parentNode;  //取得所在行
 var officeCode=row.id; //取得行的Id
 
 if(i ......

在WEB-INF下实现jsp页面的跳转

不说废话了,看下面的例子吧(利用structs实现):
在WEB-INF下有两个页面: a.jsp  和  b.jsp   ,  现在要实现从a.jsp连接到b.jsp
在a.jsp中:
                    <html:link action= ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号