如何使用了getJspContext方法来获取当前的JspContext对象

 我来答
所桖鲆0fX
2016-10-22 · 超过33用户采纳过TA的回答
知道答主
回答量:68
采纳率:0%
帮助的人:35.8万
展开全部
  • 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;

  •     }

  • }

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式