Home > Back-end >  Beginners Spring MVC, page jump 404, background cannot enter the Controller,, every brother please g
Beginners Spring MVC, page jump 404, background cannot enter the Controller,, every brother please g

Time:09-20

Beginners Spring MVC framework, recently set up a foundation to realize, can enter the situation now is front page, click to jump to 404 error, the background is also unable to enter the Controller, baidu N long also didn't solve, please show just a little big, the following is the specific configuration of the:
1. The project directory

2. The spring MVC - servlet. XML configuration
 & lt; ? The XML version="1.0" encoding="utf-8"?> 
& lt; Beans XMLNS="http://www.springframework.org/schema/beans"
XMLNS: xsi="http://www.w3.org/2001/XMLSchema-instance"
XMLNS: MVC="http://www.springframework.org/schema/mvc"
XMLNS: context="http://www.springframework.org/schema/context"
Xsi: schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd "& gt;

& lt; ! - enable the MVC annotations - & gt;
& lt; MVC: annotation - driven/& gt;

& lt; ! - the parser configuration view - & gt;
& lt; Bean id="defaultViewResolver" & gt;
& lt; ! - set the JSP file directory location - & gt;
& lt; ! -- configuration path prefix attribute, if the last or folder, still need/- & gt;
& lt; The property name="prefix" value="https://bbs.csdn.net/WEB-INF/views/"/& gt;
& lt; ! - set the view file suffix - & gt;
& lt; The property name="suffix" value="https://bbs.csdn.net/topics/.jsp"/& gt;
& lt;/bean>

& lt; ! - configure automatic assembly & gt;
& lt; Context: component - scan base - package="controller"/& gt;
& lt;/beans>

3. Web. XML configuration
 & lt; Web - app XMLNS="http://xmlns.jcp.org/xml/ns/javaee" 
XMLNS: xsi="http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
"
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsdVersion="3.1" & gt;

& lt; The display - name> HelloWorldSpring

& lt; ! - configuration for springMVC DispatcherServlet - & gt;
& lt; Servlet>
& lt; The servlet - name> Spring - mvc
& lt; The servlet - class> Org. Springframework. Web. Servlet. DispatcherServlet
& lt; Init - param>
& lt; ! - configure spring MVC - servlet. XML as the MVC configuration file - & gt;
& lt; Param - name> ContextConfigLocation
& lt; Param - value>/WEB - INF/spring MVC - servlet. Xml
& lt;/init - param>
& lt; The load - on - startup> 1
& lt;/servlet>

& lt; ! - front intercept - & gt;
& lt; The servlet - mapping>
& lt; The servlet - name> Spring - mvc
& lt; Url - pattern>/& lt;/url - pattern>
& lt;/servlet - mapping>

& lt; ! -- the root - context. XML to join in the configuration file - & gt;
& lt; The context - param>
& lt; Param - name> ContextConfigLocation
& lt; Param - value>/WEB - INF/root - context. Xml
& lt;/context - param>

& lt;/web - app>

4. The Controller
 package controller; 

The import org. Springframework. Stereotype. The Controller;
The import org. Springframework. Web. Bind. The annotation. RequestMapping;


@ Controller
Public class HelloController {
@ RequestMapping ("/success ")
Public String sayHello () {
System. The out. Println (" Hello, the SpringMVC ");
return "success";
}
}

5. The index. The JSP
 & lt; % @ page contentType="text/HTML. Charset=utf-8 "language=" Java "% & gt; 
& lt; html>
& lt; head>
& lt; title> SpringMVCDemo
& lt;/head>
& lt; body>
& lt; H1 & gt; Hello SpringMVC& lt; A href="https://bbs.csdn.net/topics/success" & gt; Click on the jump & lt;/a>
& lt;/body>
& lt;/html>

CodePudding user response:

Supplementary project directory

CodePudding user response:


Return "views/success";
Try


CodePudding user response:

Why don't your profile on the WEB - INF on resource

CodePudding user response:

The
reference 3 floor xaoqizeng response:
why don't your profile on the WEB - INF on resource


The
& lt; ! - configuration for springMVC DispatcherServlet - & gt;
& lt; Servlet>
& lt; The servlet - name> Spring - mvc
& lt; The servlet - class> Org. Springframework. Web. Servlet. DispatcherServlet
& lt; Init - param>
& lt; ! - configure spring MVC - servlet. XML as the MVC configuration file - & gt;
& lt; Param - name> ContextConfigLocation
& lt; Param - value>/WEB - INF/spring MVC - servlet. Xml
& lt;/init - param>
& lt; The load - on - startup> 1
& lt;/servlet>

Modified into

& lt; Servlet>
& lt; The servlet - name> Springmvc
& lt; The servlet - class> Org. Springframework. Web. Servlet. DispatcherServlet
& lt; Init - param>
& lt; Param - name> ContextConfigLocation
& lt; Param - value> The classpath: spring - the MVC. Xml
& lt;/init - param>
& lt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related