[英]spring mvc HTTP Status 404 -
I am trying to make a spring hello world program in eclipse. 我试图在Eclipse中制作Spring Hello世界程序。 Here is the code
这是代码
index.jsp 的index.jsp
<a href="hello.html">click</a>
HelloWorldController.java HelloWorldController.java
package com.javatpoint;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class HelloWorldController {
@RequestMapping("/hello")
public ModelAndView helloWorld() {
String message = "HELLO SPRING MVC HOW R U";
return new ModelAndView("hellopage", "message", message);
}
}
web.xml web.xml中
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<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>*.html</url-pattern>
</servlet-mapping>
</web-app>
spring-servlet.xml 为spring-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">
<context:component-scan base-package="com.javatpoint" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
hellopage.jsp hellopage.jsp
Message is: ${message}
When I go to http://localhost:8080/SpringMVCBasic/ , I gets the index.jsp page correctly open 当我转到http:// localhost:8080 / SpringMVCBasic /时 ,我正确打开了index.jsp页面
but when I click on link on the page ie the url http://localhost:8080/SpringMVCBasic/hello.html , I gets the error 但是当我单击页面上的链接即URL http:// localhost:8080 / SpringMVCBasic / hello.html时 ,出现了错误
HTTP Status 404 -
When I use url like this http://localhost:8080/SpringMVCBasic/hello , I gets this 当我使用像这样的URL http:// localhost:8080 / SpringMVCBasic / hello时 ,我得到了
HTTP Status 404 - /SpringMVCBasic/hello
You provided mapping for: 您提供了以下映射:
@RequestMapping("/hello")
but you have to do it for: 但您必须这样做:
@RequestMapping("/hello.html")
I downloaded the eclipse project and run it on a jboss. 我下载了eclipse项目并在jboss上运行它。 Following jars needed to be included:
需要包括以下罐子:
If i afterwards run the jboss with Java 8 all seems to work fine. 如果我之后用Java 8运行jboss,一切似乎都可以正常工作。
在spring-servlet.xml中启用Spring MVC @Controller编程模型,如下所示:
<mvc:annotation-driven />
In your index.jsp instead of writing 在您的index.jsp中,而不是编写
href="hello.html">
change to
href="./hello.html">
and 和
In HelloworldController.java
instead of writing 在
HelloworldController.java
而不是编写
@RequestMapping("/hello")
change to:- 改成:-
@RequestMapping(value="/hello.html")
Please add all these jar as external jar or add these jar to your lib folder 请将所有这些jar添加为外部jar或将这些jar添加到您的lib文件夹中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.