3

I have faced the problem when decided to create a web-app without JSPs, but using only HTML-pages which are under directory WEB-INF/pages.

I've made the view resolver:

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

Also I've imported all the resources in WEB-INF/pages:

<mvc:resources mapping="/**" location="WEB-INF/pages/"/>

My controller have the following view:

@PreAuthorize("isAuthenticated()")
@RequestMapping("/")
public String indexPage() {
    return "redirect:/index.html";
}

It works fine for mapping "/" (redirects to login page if not authenticated), but it is not secured for url "/index.html" due to importing of this page as static resource (but it will not work at all if not import it).

2 Answers 2

3

Finally, I found the solution. Maybe, it will be interesting to anybody. The main servlet mapping that I had, had url-pattern: /** And that was my problem. As I understood the main servlet in someway intercepted viewResolver even if it had such configuration: <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/pages/"/> <property name="suffix" value=".html"/> </bean>

When I make the configuration of servlet make as the next one:

  <servlet-mapping>
    <servlet-name>main</servlet-name>
    <url-pattern>/app/*</url-pattern>
</servlet-mapping>

everything became ok.

Sign up to request clarification or add additional context in comments.

1 Comment

The /app pattern (or something similar) helps us distinguish Dispatcher- Servlet -served content from other types of content. But then we have an implementation detail (specifically, the /app path) exposed in our URL s. That leads to complicated URL rewriting tactics to hide the /app path. Spring in Action 3rd Edition page 192
0

i dont know why you want to do that ..... as putting pages under web-inf is a wrong practice.......

also the container cant access the static contents that are under web-inf folder. I have faced exactly same problem see resource problem post.

what i have found from googling is you can access dynamic resources under web-inf folder but not the static. I have tried even regestring all the static contents (ie. css, js,html, etc) in xml at the first place but nothing worked. finally i moved my pages out and it worked with no configuration ....

so try moving the resources out of web-inf and under webcontent

tell me if you got some extras on this.

thanks.

1 Comment

Actually it's good practice to put files that just serve as views under WEB-INF, to hide them from direct access

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.