Redirect one jsp folder into another jsp folder is

2019-09-19 01:56发布

问题:

I have a question on redirect page one folder into another folder of jsp pages. I defined viewResolver:

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property> 
    <property name="prefix"><value>/jsp/</value></property>
    <property name="suffix"><value>.jsp</value></property>
</bean>

But My folder struture is

WEB-ROOT
      |__JSP
              |__user
                      |_userdashboardpage.jsp
     |__loginpage.jsp
     |__web.xml

Iam trying to validate the user details e.g. username, password when the logged the user page using validator interface. But if any error occurs while entered the blank details then occured errors and redirect the same page i.e, loginpage using getFormView method with prefix property in viewResolver bean.

But errors is not displaying in the same page. The container looking /jsp/loginpage. But my page having outside jsp folder. If iam removing the prefix then it shows errors.

So how to redirect the page one folder jsp into another folder jsp or web-root into jsp>user>userdashboard.jsp. How to dispay the error in this scenario. Can i go to chain view resolvers?

回答1:

The prefix property of your InternalResourceViewResolver shouldn't go any deeper than the top of your JSP hierarchy. Since not all of your JSPs are under /jsp, you can't use that as your prefix.

So remove the prefix property, and use the appropriate view names. So to use jsp/user/userdashboardpage.jsp, you should return the view name jsp/user/userdashboardpage from your controller. To use loginpage.jsp, return just loginpage.

Can i go to chain view resolvers.

No. Multiple InternalResourceViewResolver cannot be chained, due to the way the servlet API works.



标签: spring-mvc