I am using Spring 3.2.7, I have Login.jsp file which takes the input and should display the output on hello.jsp, it takes the input but does not show an output instead it throws an error as HTTP Status 404 - Not Found
. Here is the code:
@Controller
public class HelloWorldController {
@RequestMapping("/hello")
public ModelAndView helloWorld(HttpServletRequest request, HttpServletResponse response) {
String name = request.getParameter("name");
String password = request.getParameter("password");
if (password.equals("admin")) {
String message = "Hello " + name;
return new ModelAndView("hellopage", "message", message);
} else {
return new ModelAndView("errorpage", "message", "Sorry Username or Password Error");
}
}
}
Dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:component-scan base-package="mypack" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
</beans>
After observing your Dispatcher-servlet.xml, I can see you are missing
<mvc:annotation-driven/>
Your Updated code will look like belowExplanation