zoukankan      html  css  js  c++  java
  • 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
    欢迎任何形式的转载,但请务必注明出处。
    分享到:
  • 相关阅读:
    Qt 学习之路:元素布局
    Qt 学习之路 2(80):定位器
    Qt 学习之路 2(79):QML 组件
    Qt 学习之路:QML 组件
    Qt 学习之路:QML 基本元素
    qt 学习之路 :QML 语法
    Qt 学习之路:QML 和 QtQuick 2
    Qt 学习之路:线程总结
    Qt 学习之路:线程和 QObject
    五步教你实现使用Nginx+uWSGI+Django方法部署Django程序
  • 原文地址:https://www.cnblogs.com/xwdreamer/p/2297083.html
Copyright © 2011-2022 走看看