Hi, I find it difficult to find the following URL:
<a href="/noticeOpen/2">dynamicLink</a>
to display with the following controller method:
@RequestMapping(value="/noticeOpen/{quesId}") public ModelAndView noticeOpen(@ModelAttribute("NoticeForm") NoticeForm noticeForm, ModelMap model, @PathVariable("quesId") Integer quesId){ System.out.println(quesId); return new ModelAndView("/noticeOpen","noticeForm",noticeForm); }
The problem starts when I click on anchor dynamicLink and does not transfer control to my controller, instead it shows the following in the address bar of the browser:
http://127.0.0.1:8080/prj/noticeOpen/2/WEB-INF/pages/noticeOpen.jsp
In addition, I have the following mapping in applicationContext.xml
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix"> <value>WEB-INF/pages/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean>
This all works fine if I remove {quesId} from the @RequestMapping controller and @PathParam from the method signature (also remove the questionId from the binding)
http:
But it does not sound dynamic and does not meet my requirement.
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <display-name>Spring Web MVC Application</display-name> <servlet> <servlet-name>mvc-dispatcher</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvc-dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> </web-app>
Update
I created a new controller for /noticeOpen/{quesId} and now I have control, but I can not understand the behavior of the following methods. Please take a look at NoticeController below and then the result:
@Controller public class NoticeController { @RequestMapping(value="/noticeOpen/{quesId}") public ModelAndView noticeOpen(@ModelAttribute("NoticeForm") NoticeForm noticeForm,ModelMap model,@PathVariable("quesId") Integer quesId){ return new ModelAndView("noticeOpen","noticeForm",noticeForm); } @RequestMapping(value="/noticeOpen") public ModelAndView noticeOpen(@ModelAttribute("NoticeForm") NoticeForm noticeForm,ModelMap model){ return new ModelAndView("noticeOpen","noticeForm",noticeForm); }
@RequestMapping(value="/noticeOpen") it redirects me to fix noticeOpen.jsp @RequestMapping(value="/noticeOpen/{quesId}") it redirects me to the next error page
HTTP Status 404 - /prj/noticeOpen/WEB-INF/pages/noticeOpen.jsp type Status report message /prj/noticeOpen/WEB-INF/pages/noticeOpen.jsp description The requested resource is not available. Apache Tomcat/6.0.36