Reputation: 47
spring-servlet.xml
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value=".jsp" />
</bean>
controller class
@RequestMapping(value="/admissionForm.html", method = RequestMethod.GET)
public ModelAndView getAdmissionForm() {
ModelAndView model = new ModelAndView("AdmissionForm");
return model;
}
@RequestMapping(value="/admissionForm.jsp", method = RequestMethod.GET)
public ModelAndView getAdmissionForm2() {
ModelAndView model = new ModelAndView("AdmissionForm");
return model;
}
@RequestMapping(value="/admissionForm", method = RequestMethod.GET)
public ModelAndView getAdmissionForm3() {
ModelAndView model = new ModelAndView("AdmissionForm");
return model;
}
web.xml
<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
whenever i am accessing the url through /admissionForm.html and /admissionForm i am getting response in webpage but when i access through /admissionForm.jsp i am getting 404 page not found ,my question is what's the reason for this and what i could do to make this work?
Upvotes: 1
Views: 901
Reputation: 437
change in web.xml file
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Upvotes: 2
Reputation: 53793
First, I am not sure if its for example or your real code but it the mehods are the same you can write
@RequestMapping(value={"/admissionForm","/admissionForm.htm","/admissionForm.html"}, method = RequestMethod.GET)
For your issue, you can try to change your web.xml to
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>*</url-pattern>
</servlet-mapping>
so it will recognize the jsp
extension
Upvotes: 1