iteye_20815
iteye_20815
2008-09-09 16:08
浏览 310
已采纳

在struts中关于HttpServletRequestWrapper的问题。。。

我在代码中继承了类HttpServletRequestWrapper,代码如下:
[code="java"]
public class MyRequestWrapper extends HttpServletRequestWrapper {

HttpSession iSession = null;

public MyRequestWrapper(HttpServletRequest request) {
    super(request);
}

   public HttpSession getSession() {
    if (null != iSession) {
        return iSession;
    }
    return super.getSession();
}

public HttpSession getSession(boolean create) {
    if (null != iSession) {
        return iSession;
    }
    return super.getSession(create);
}

public void setSession(HttpSession iSession) {
    this.iSession = iSession;
}

}
[/code]

而我在struts Action接受到页面提交过来的信息时,初始化了该类(MyRequestWrapper),Action代码如下:
[code="java"]
public ActionForward login(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {

 .........

 MyRequestWrapper wrapperRequest = (MyRequestWrapper) request;

 .........

}

[/code]

[b][color=red]可是出错了:[/color][/b]

[color=red]java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade[/color]
[color=red]at com.redMud.web.action.LoginAction.login(LoginAction.java:68)[/color]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:274)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.shareinfo.common.util.EncodingFilter.doFilter(EncodingFilter.java:37)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:833)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:639)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1285)
at java.lang.Thread.run(Thread.java:595)

这个问题有哪位朋友遇到过的吗?帮忙解答一下,谢。。。

PS:能说说HttpServletRequestWrapper 具体的用法吗?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • heroslt
    heroslt 2008-09-09 16:44
    已采纳

    应该这样写:

    [code="java"]
    public ActionForward login(ActionMapping mapping, ActionForm form,

    HttpServletRequest request, HttpServletResponse response) {

     .........   
    
     MyRequestWrapper wrapperRequest = new MyRequestWrapper(request);   
    
     .........   
    

    }

    [/code]

    点赞 评论

相关推荐