I google a lot and get a answer:
<c:out value="${pageContext.request.requestURI}" />
But I get /myapp/WEB-INF/views/index.jsp
I want to get /myapp/index
How can I do that?
My project is using spring mvc. My config in spring-mvc.xml:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
In my /WEB-INF/views/, has a index.jsp
My Controler:
@RequestMapping("/index")
public String welcome() {
return "index";
}
When I view localhost:8088/myapp/index
, It shows.
Try to use ${requestScope['javax.servlet.forward.servlet_path']}
javax.servlet.forward.*
constants retrieve information based on URI passed to getRequestDispatcher()
(DispatcherServlet sets this attribute while handling request in the case of Spring Web MVC). But it's independent of frameworks and web containers.
As documentation says FORWARD_SERVLET_PATH
is:
The name of the request attribute under which the original servlet path is made available to the target of a forward
You should also remember that if the forward()
works by calling getNamedDispatcher()
, these attributes (there are 4 more similar attributes: request_uri
, context_path
, path_info
and query_string
) are not set because in this case the initial elements of the path does not change.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With