开发者

Spring: Resolve view names to .jsp files in /WEB-INF

开发者 https://www.devze.com 2023-02-17 14:13 出处:网络
I have many .jsp files in /WEB-INF/views/*.jsp that I\'d like to resolve like this: GET http://localhost:8080/myapp/doggystyle/ -> /WEB-INF/views/doggystyle.jsp

I have many .jsp files in /WEB-INF/views/*.jsp that I'd like to resolve like this:

GET http://localhost:8080/myapp/doggystyle/ -> /WEB-INF/views/doggystyle.jsp

How do I do this without specifying each r开发者_如何学Goesource in my @Controller?


Could you try using a UrlBasedViewResolver?

<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    <property name="prefix" value="/WEB-INF/views/"/>
    <property name="suffix" value=".jsp"/>
</bean>

I am a bit confused because you mention @Controller and JSPs are for views not controllers. Hopefully this is what you're needing.


<bean   class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>

This is enough. Your call to GET http://localhost:8080/myapp/doggystyle will be internall processed as GET http://localhost:8080/myapp//WEB-INF/views/doggystyle.jsp

If you are are using a Controller:

@Controller
public class MyController
{
   @RequestMapping(value = "/doggystyle", method = RequestMethod.GET)
   public String getForm(Model model){
      return("doggystyle");
   }
}

That should do. That should do. Good Luck.


You can read that article regarding viewresolver

http://docs.spring.io/spring-framework/docs/2.0.x/reference/mvc.html

13.5.1. Resolving views - the ViewResolver interface

0

精彩评论

暂无评论...
验证码 换一张
取 消