Announcement Announcement Module
Collapse
No announcement yet.
InternalResourceViewResolver only for certain requests? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • InternalResourceViewResolver only for certain requests?

    Hey,
    first of all I’m a Spring noob, and yes I used the search function, so please be kind . I did the Spring 2.5 MVC tutorial and everything works fine.
    Now I want to extend the current application by adding some simple jsp pages to the WEB-INF folder. To keep the application very simple I forward all http requests to my Dispatcher Servlet.
    Code:
    <servlet-mapping>
      <servlet-name>springapp</servlet-name> 
      <url-pattern>/</url-pattern> 
      </servlet-mapping>
    Then I added an UrlFilenameViewController (that catches all requests that are not catched by other controllers).
    Code:
    <bean name="/**/*.*" class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> 
      <property name="prefix" value="/WEB-INF/jsp/" /> 
      <property name="suffix" value=".jsp" /> 
      </bean>
    While this works fine for simple jsp pages, I get an error if I try to access, js, images, css … files within these jsp pages. Is there a simple way to control which “kind” of requests are directly forwarded to the WEB-INF folder (e.g. requests for images in my WEB-INF/img folder) and which requests are modified by the viewResolver (e.g. all requests with urls that that end with *.jsp, *.html or *.htm)?

  • #2
    Hey,

    Since you map dispatcher to the root path "/", then all requests are sending to spring dispatcher, and thus you get error for non dynamic content(spring) like js and images. You only want your jsp request to spring dispatcher, while other resource back to the server to handle. To do this you simply map your dispatcher to distinct name like "/spring", or "/webapp" instead of just "/". Many other uses extension suffix mapping to dispatcher too, like "*.action", or "*.jspa" things like that. These setting will avoid conflict with your js, images and css files requests.

    Comment


    • #3
      thank you for your reply. In your solution everybody could access these static objects (pictures, js scripts etc). But, I want to extend my application later and control who is allowed to see the content of my application (including static content like pictures and js).

      Comment

      Working...
      X