我看起來像一個菜鳥錯誤,但似乎我無法通過它。我正在學習JSP和Spring,並且在我的項目中遇到了404錯誤。 我正在使用一個tomcat 8.0本地服務器。我的目標是從「http://localhost:8080/TestSpring/vues/bonjour.jsp」去「http://localhost:8080/TestSpring/bonjour」有教程的幫助,但是這會導致一個404簡單的JSP頁面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>
bonjour.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";
}
}
如果它可能會幫助,該項目。
感謝提前:)
是您的應用程序成功地部署在服務器? –
@Subodh是的,我想是的(如果這是你的意思,部署[鏈接](http://imgur.com/AOrBi8l)),並有我的服務器啓動時的控制檯文本,我嘗試連接到URL 。 [鏈接](http://pastebin.com/zvXLQfn7) – Erunayc
在日誌中會清楚地顯示項目是否已部署 –