我正在从书中弹簧食谱中制作一个示例,并且我似乎无法将示例部署到 tomcat 中。我正在尝试打开 messageList.htm 页面,但我总是收到 HTTP 状态 404 错误。
有人可以帮助我吗?
提前谢谢
这是代码:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<:web-app version="2.4" xmlns:="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
<:context-param>
<:param-name>contextConfigLocation</:param-name>
<:param-value>/WEB-INF/board-service.xml</:param-value>
</:context-param>
<:listener>
<:listener-class>org.springframework.web.context.ContextLoaderListener</:listener-class>
</:listener>
<:servlet>
<:servlet-name>Chapter5Security</:servlet-name>
<:servlet-class>org.springframework.web.servlet.DispatcherServlet</:servlet-class>
</:servlet>
<:servlet-mapping>
<:servlet-name>Chapter5Security</:servlet-name>
<:url-pattern>/*</:url-pattern>
</:servlet-mapping>
</:web-app>
板服务.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean id="messageBoardService" class="service.MessageBoardServiceImpl" />
</beans>
板-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: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="web"></context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
消息列表控制器
@Controller
@RequestMapping("/messageList*")
public class MessageListController {
private MessageBoardService messageBoardService;
@Autowired
public MessageListController(MessageBoardService messageBoardService)
{
this.messageBoardService=messageBoardService;
}
@RequestMapping(method= RequestMethod.GET)
public String generateList(Model model)
{
List<Message>messages=java.util.Collections.emptyList();
messages=messageBoardService.ListMessages();
model.addAttribute("messages",messages);
return "messageList";
}
}
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>be.glennvdv.BookSpring</groupId>
<artifactId>Chapter5Security</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Chapter5Security Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-acl</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
</dependencies>
<build>
<finalName>Chapter5Security</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<server>myserver</server>
</configuration>
</plugin>
</plugins>
</build>
</project>
消息列表.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>Message List</title>
</head>
<body>
<c:forEach items="${messages}" var="message">
<table>
<tr>
<td>Author</td>
<td>${message.author}</td>
</tr>
<tr>
<td>Title</td>
<td>${message.title}</td>
</tr>
<tr>
<td>Body</td>
<td>${message.body}</td>
</tr>
<tr>
<td colspan="2">
<a href="messageDelete?messageId=${message.id}">Delete</a>
</td>
</tr>
</table>
<hr />
</c:forEach>
<a href="messagePost">Post</a>
</body>
</html>