我在quiz.jsp
中有一个链接,如果我点击该链接,那么它必须转到play.jsp
,但它正在向我提供错误请求的资源未找到
quiz.jsp
<%@ 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">
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>play quiz</title>
</head>
<body>
Welcome ${name}
<a href="play.jsp">Play quiz</a>
</body>
</html>
弹簧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.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- telling container to take care of annotations stuff -->
<context:annotation-config />
<context:component-scan base-package="com.quiz"></context:component-scan>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean id="user" class="com.quiz.model.user"></bean>
<bean id="userDaoImpl" class="com.quiz.dao.UserDaoImpl"></bean>
<!-- declare datasource bean -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/quiz" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
</beans>
的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: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"
id="WebApp_ID" version="2.5">
<display-name>QUIZ</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-
class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
HomePageController.java
@Controller
public class HomePageController {
@Autowired
UserDaoImpl userDaoImpl;
@RequestMapping("/register")
public ModelAndView registerUser(@ModelAttribute user use){
return new ModelAndView("register");
}
@RequestMapping("/insert")
public ModelAndView successMessage(@ModelAttribute user use){
if(use != null){
userDaoImpl.insertData(use);
}
return new ModelAndView("success" ,"name", use.getuName());
}
@RequestMapping("/login")
public ModelAndView getUserList(@ModelAttribute user u){
List<user> userList = userDaoImpl.getData();
int len = userList.size();
for(int i = 0;i<= len ; i++){
String userr = userList.get(i).getuName();
if(userr.equals(u.getuName())){
return new ModelAndView("quiz","name", u.getuName());
}
}
return new ModelAndView("register");
}
@RequestMapping("/userSign")
public ModelAndView getUser(String name){
List<user> userList = userDaoImpl.getData();
int len = userList.size();
for(int i = 0;i<= len ; i++){
String userr = userList.get(i).getuName();
if(userr.equals(name)){
return new ModelAndView("quiz","name", name);
}
}
return new ModelAndView("error","name",name);
}
}