ServletActionContext.getRequest().getServletPath()错误的解决方法

简介:

BaseAction

package control.util;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ActionContext;
public class BaseAction extends ActionSupport {
    private static final long serialVersionUID = 1L;
    // 取得当前登录的用户名
    protected String getLoginUsername() {
        return (String) ActionContext.getContext().getSession().get(
                Constants.USERNAME_KEY);
    }
    // 判断当前用户是否超时
    protected boolean isTimeout() {
        if (ActionContext.getContext().getSession().get(Constants.USERNAME_KEY) == null) {
            return true;
        } else {
            return false;
        }
    }
    // 检查Session对象是否存在
    protected boolean isExistSession(String key) {
        if (ActionContext.getContext().getSession().get(key) != null) {
            return true;
        } else {
            return false;
        }
    }
    // 保存Session对象 
    @SuppressWarnings("unchecked")
    protected void setSession(Object key, Object obj) {
        ActionContext.getContext().getSession().put(key, obj);
    }
    // 取得Session对象
    protected Object getSession(String key) {
        return ActionContext.getContext().getSession().get(key);
    }
    // 保存一条错误
    protected void saveActionError(String key) {
        super.addActionError(super.getText(key));
    }
    // 保存一个消息
    protected void saveActionMessage(String key) {
        super.addActionMessage(super.getText(key));
    }
    // 取得查询的URL
    protected String getRequestPath() {        
        return (String) ServletActionContext.getRequest().getServletPath();
    }
}
在BaseAction中调用ServletActionContext.getRequest().getServletPath()显示错误。
ServletActionContext.getRequest().getServletPath();是在%tomcatHome%/lib/servlet-api.jar中,而lib中没有添加servlet-api.jar,所以会显示错误。

解决方法:在lib中添加servlet-api.jar,或者添加Library中引用servlet-api.jar。







本文转自xwdreamer博客园博客,原文链接:http://www.cnblogs.com/xwdreamer/archive/2010/09/26/2297083.html,如需转载请自行联系原作者

目录
相关文章
|
10月前
|
安全 网络架构
电脑维修常遇到等等相关问题及解决方法?
电脑维修常遇到等等相关问题及解决方法?
|
12月前
|
数据库
学生错误‘3704‘解决方法
学生错误‘3704‘解决方法
|
弹性计算 应用服务中间件 Apache
502 错误
502 错误
774 0
|
索引
错误
错误
212 0
|
应用服务中间件 nginx
今日所遇到的问题+解决方法
今日在阿里云轻量应用服务器部署LNMP时所遇问题
|
小程序 Android开发
排查指南 | 当 mPaaS 小程序提示“应用更新错误(1001)”时
APP 启动 mPaaS 小程序弹出 toast 信息:"应用更新错误"。
3588 0
排查指南 | 当 mPaaS 小程序提示“应用更新错误(1001)”时