English 中文(简体)
jsp 错误 jsp 错误Page 弹簧调度器工作不当
原标题:jsp errorPage not working properly with spring dispatcher

我使用春天 在我的JSP项目:

我对所有 HTML 请求进行映射 :

<servlet>
  <servlet-name>spring</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
   <servlet-name>spring</servlet-name>
   <url-pattern>*.html</url-pattern>
</servlet-mapping>

所以每个请求都交给调度员

我有一个 JSP 页面, 它有 session.getAttritte () , 将会话变量返回到该页面 。

如果某些用户直接访问该页面,则会话变量返回为空。

为避免这种情况,我试图在联合战略规划网页中增加以下一行:

<%@page errorPage="error.jsp"%>

JSP 文件位于该页面所在的同一目录中, 但没有运气 。 我得到了以下例外 : -- & gt; 404

我还尝试了一个组合,所以错误页面会指出如下:

仍然无效

然后,我在主计长中增加了一个条目如下:

 @RequestMapping("/xyz/result/error")
        public ModelAndView showErrorPageEng() {
            return new ModelAndView("errorpage", "comm和", null);
        }

问题的最新部分:

我有以下错误页的牌项:

<definition name="errorpage" extends="basic"
    template="/error/error_layout.jsp">
    <put-attribute name="error" value="/error/error.jsp"/>  
</definition>

并修改JSP的代码如下:

<%@page errorPage="error.html"%>

上述路径/xyz/结果/错误如下:

ROOT/xyz/result/error

我可以访问文件mydomain/xyz/result/error.html ,但是没有发生同样的情况,但以下例外:

<强 > 启动为

at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:745)
at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:716)
at org.apache.jsp.error_jsp._jspService(error_jsp.java:63)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:745)


**和 ends as** 

    at org.apache.tiles.servlet.context.ServletTilesRequestContext.dispatch(ServletTilesRequestContext.java:220)
    at org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)
    at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:103)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:659)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:678)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:633)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:322)
    at org.springframework.web.servlet.view.tiles2.TilesView.renderMergedOutputModel(TilesView.java:124)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549

)

最佳回答

以@pradeeps 现有解决方案为基础的另一种可能的解决办法是使用 HttpServletResponse 对象重定向到静态 HTML 页面。

虽然静止的 HTML 页面无法在 JSP scriplet 页面声明中使用, 浏览器可访问的现有路径是服务器可以将用户重新定向到的东西 。

这种解决方案的优点在于 HTML 保存在 HTML 文件的所属位置, 而不是在 Java 字符串中。 这创造了一个更可维护的环境, 使 Java 工程师可以读取代码, Web 开发者也可以读取代码, 但是仍然建立在拟议工作选项之上 。

<强>贾瓦:

String  myObject= (String)session.getAttribute("finalList");

    if(myObject==null)
        {

            // redirect to the error page, using static HTML
            response.sendRedirect("/errorPage.html");
            return;

        }

<强>errorPage.html:

<html>
<head></head>
<body>
  <div class="content">
    <div class="mainbarWH">
        <div class="article">
        <h2 class="style1">Sorry !</h2>
        <div class="clr style1"></div>
        <p class="style1">
            <strong>Your session has been expired </strong>
        </p>
        <p class="style1">Please go to <a href="engineering.html">Home</a></p>
     </div>
   </div>
   <div class="clr"></div> </div>
</body>
</html>
问题回答

我们找到了可能的变通方法如下, 我们可以把这个放在jsp页面上, 我不知道,但把回馈作品,

String  myObject= (String)session.getAttribute("finalList");

    if(myObject==null)
        {
            out.println("<div class="content">     <div class="mainbarWH">       <div class="article">         <h2 class="style1">Sorry !</h2>         <div class="clr style1"></div>         <p class="style1"><strong>Your session has been expired </strong></p>         <p class="style1">Please go to <a href="engineering.html">Home</a></p>       </div>       </div>     <div class="clr"></div> </div>");
            return;

        }

jsp 页面

x - tile y - tile z - tile in a jsp page and if null pointer exception comes in tile y ,

然后在代码上方给定页面为,

x -tile y - tile

所以,在回去的时候,我们只是做了出来。 println(一些 html 代码)

这仅仅是变通办法, 尚未达到标准解决方案





相关问题
Convert typed-in Text to lowercase

I ve got an index.jsp with [snip] <% String name = request.getParameter("name"); String pass = request.getParameter("pass"); String globalname = "webeng"; String globalpass = "2009"; ...

session transfer issue from Tomcat to ASP.Net

I am using Tomcat to host JSP and using IIS 7.0 to host aspx (C# + .Net 3.5 + VSTS 2008), and I have some session transfer issue from JSP page to ASPX page. JSP page is in one domain and all other ...

Setting the default value in Struts2

I am setting the value(kind of default value) for a drop down select value from action class in a page(given below). When the page loads the value is beig displayed but the other elements of the ...

Evaluate dynamically constructed JSP at runtime

I have a requirement where in the JSP page itself is created by the user and stored in the database. When viewing results we need to render this JSP to the client, evaluating all tags inside this JSP. ...

How to Pack/Encrypt/Unpack/Decrypt a bunch of files in Java?

I m essentially trying to do the following on a Java/JSP-driven web site: User supplies a password Password is used to build a strongly-encrypted archive file (zip, or anything else) containing a ...

JSP exception - class not found (tomcat)

I m setting up an existing application on a new Tomcat 5.5 server connecting to a Postgres database (running on Debian Lenny). When I access it I get a series of stack traces with the following root ...

ArrayList to Table in JSP

I have an ArrayList and i am trying to display it in a table ..... ArrayList rows = .... ..... <table cellspacing="1" cellpadding="4" border="3"> <tr> <TH>...

热门标签