我有一个看起来像菜鸟错误的东西,但我似乎无法克服它。我正在学习 JSP 和 Spring,但在我的项目中遇到了 404 错误。 我正在使用 tomcat 8.0 本地服务器。我的目标是在教程的帮助下从“http://localhost:8080/TestSpring/vues/bonjour.jsp”转到“http://localhost:8080/TestSpring/bonjour”,但这会导致 404。
“调度程序-servlet.xml”
<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" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:component-scan base-package="be.knoware" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/vues/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="ISO-8859-1" />
</bean>
网络.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Declaration de la servlet de Spring et de son mapping -->
<servlet>
<servlet-name>servlet-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>servlet-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
你好.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" isELIgnored="false"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><spring:message code="titre.bonjour"/> ${personne}</title>
</head>
<body>
<spring:message code="libelle.bonjour.lemonde" arguments="${personne}"/>
</body>
</html>
BonjourController.java
package controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/bonjour")
public class BonjourController {
@RequestMapping(method = RequestMethod.GET)
public String afficherBonjour(final ModelMap pModel){
pModel.addAttribute("personne","Jim");
return "bonjour";
}
}
如果可能有帮助,项目。
提前致谢:)
最佳答案
如果存在一些部署问题或服务器问题,您可以执行一些步骤
- 清理并构建项目并将 war 文件复制到您的服务器
- 在更新 war 文件之前,您必须关闭 tomcat 或服务器。
- 启动服务器并打开 URL 并检查是否自动提取 war 如果是则服务器没有问题。
- 检查 URL 和日志文件以获得更好的保证。 乐于助人
关于java - 简单的jsp页面出现404错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32134281/