報(bào)404,找不到hello.jsp頁(yè)面怎么辦?跪求解答!!
訪問(wèn)地址:http://localhost:8080/ZLearnSpringMvc/hello/mvc
其中ZLearnSpringMvc是我的項(xiàng)目名
項(xiàng)目結(jié)構(gòu):
mvc-dispatcher-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"????? ???????xmlns:mvc="http://www.springframework.org/schema/mvc" ??? ???xsi:schemaLocation=" ??? ????http://www.springframework.org/schema/beans? http://www.springframework.org/schema/beans/spring-beans.xsd?? http://www.springframework.org/schema/context? http://www.springframework.org/schema/context/spring-context.xsd? http://www.springframework.org/schema/mvc? http://www.springframework.org/schema/mvc/spring-mvc.xsd"> ????<!--?啟用spring?mvc?注解?--> ????<context:annotation-config?/> ????<!--?設(shè)置使用注解的類所在的jar包?--> ????<context:component-scan?base-package="com.cbt.controller"> ???? <context:include-filter?type="annotation"?expression="org.springframework.stereotype.Controller"?/> ????</context:component-scan> <mvc:default-servlet-handler/> <mvc:annotation-driven?/> ????<!--?對(duì)轉(zhuǎn)向頁(yè)面的路徑解析。prefix:前綴,?suffix:后綴?--> ????<bean?class="org.springframework.web.servlet.view.InternalResourceViewResolver"> ???? <property?name="viewClass"?value="org.springframework.web.servlet.view.JstlView"></property> ???? <property?name="prefix"?value="/WEB-INF/jsps/"></property> ???? <property?name="suffix"?value=".jsp"></property> ????</bean> </beans>
web.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> ??<display-name>Archetype?Created?Web?Application</display-name> ?? ??<servlet> ?? <servlet-name>mvc-dispatcher</servlet-name> ?? <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> ?? <init-param> ?? <param-name>contextConfigLocation</param-name> ?? <param-value>/WEB-INF/configs/spring/mvc-dispatcher-servlet.xml</param-value> ?? </init-param> ?? <load-on-startup>1</load-on-startup> ??</servlet> ?? ??<servlet-mapping> ?? <servlet-name>mvc-dispatcher</servlet-name> ?? <url-pattern>/</url-pattern> ??</servlet-mapping> </web-app>
HelloMvcController.java :
package?com.cbt.controller; import?org.springframework.stereotype.Controller; import?org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping("/hello") public?class?HelloMvcController?{ @RequestMapping("/mvc") public?String?helloMvc(){ System.out.println("hello"); return?"hello"; } }
2020-03-16
為什么是home呢?
2017-05-11
找到原因了,controller里應(yīng)該return "home"而不是return "hello",醉醉的,老太太我都不扶,我就服我自己?。?/p>