如何使用了getJspContext方法来获取当前的JspContext对象
jsp中取得ActionContext.getContext().put进去的值方式如下:
package com.augur.actions;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class LoginAction extends ActionSupport
{
private String username;
private String password;
private String tip;
//get,set方法略
public String login() throws Exception
{
ActionContext ctx = ActionContext.getContext();//拿到actioncontext对象,拿出里面的键值对
Integer counter = (Integer)ctx.getApplication().get("counter");
if(counter == null)
{
counter = 1;
}
else
{
counter++;
}
ctx.getApplication().put("counter", counter);
ctx.getSession().put("user", getUsername());
if("xpj".equals(getUsername()) && "xpj".equals(getPassword()))
{
System.out.println("验证通过。。。");
ctx.put("tip", "服务器提示:您已成功登陆!");
return ActionSupport.SUCCESS;
}
else
{
System.out.println("验证失败....");
ctx.put("tip","服务器提示:登陆失败!");
return ActionSupport.ERROR;
}
}
public String regist() throws Exception
{
ActionContext ac = ActionContext.getContext();
ac.put("tip","您已经成功登陆注册界面2");
return SUCCESS;
}
}