How to get uri request using jstl in spring mvc project?
I google a lot and get an 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 this?
My project uses spring mvc. My configuration 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 /, it has index.jsp
My controller:
@RequestMapping("/index") public String welcome() { return "index"; } When I look at localhost:8088/myapp/index , it shows.
Try using ${requestScope['javax.servlet.forward.servlet_path']}
javax.servlet.forward.* retrieve information based on the URI passed to getRequestDispatcher() (DispatcherServlet sets this attribute when processing the request in the case of Spring Web MVC). But it does not depend on frameworks and web containers.
As the documentation says, FORWARD_SERVLET_PATH :
The name of the request attribute at which the source servlet path becomes available for direct
You should also remember that if forward() works by calling getNamedDispatcher() , these attributes (there are 4 more identical attributes: request_uri , context_path , path_info and query_string ) are not set, because in this case the original elements of the path do not change.