这是主控制器类。登录后,我希望它重定向到LoggedIn.jsp
页面,但我收到404错误。请帮忙。
我仍然没有提供任何登录验证代码。我只想看看重定向是如何工作的。我是初学MVC及其概念的新手。请为我提供相同的建议和解决方案。
所有代码文件如下:
package com.example.myproject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
//import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class HelloController {
@RequestMapping(value="/HelloPage" , method=RequestMethod.GET)
public String showLoginForm()
{
return "HelloPage";
}
@RequestMapping(value="/redirect" , method=RequestMethod.GET)
public String redirectPage()
{
return "redirect:LoggedIn";
}
@RequestMapping(value="/LoggedIn" , method =RequestMethod.GET)
public String redirectLoggedIn()
{
return "LoggedIn";
}
}
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<!--<link rel="stylesheet" href="SpringMVCProject/CSS/CSSHelloPage.css" type="text/css" />-->
<title>Employee Management</title>
</head>
<body>
<h3 align="center" style="font-family: sans-serif;color: brown; font-size: 40px;"> Employee Management System</h3>
<form action="/spring-dispatcher/redirect" method="POST">
<table border=2 align="center" cellpadding="20">
<tr>
<td>User name</td>
<td><input type="text" name="LoginTextBox" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="PasswordTextBox" /></td>
</tr>
<tr>
<td><button name="SubmitButton" >Submit</button></td>
<td> <button name="CancelButton" >Cancel</button></td>
</tr>
</table>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<p align="center"> You have logged in successfully !</p>
</body>
</html>
<?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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<mvc:annotation-driven></mvc:annotation-driven>
<context:component-scan base-package="com.example.myproject" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
<?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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>SpringMVCProject</display-name>
<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name><param-value>/WEB-INF/spring-dispatcher-servlet.xml</param-value></init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>