发表于: 2019-11-30 23:40:46
1 1165
今天完成的事情:
重新搭建了一个mvc
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<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.xsd"
version="3.1">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextCleanupListener</listener-class>
</listener>
<!--配置前端控制器-->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<!--拦截请求-->
<!-- 1. /* 拦截所有 jsp js png .css 真的全拦截 建议不使用-->
<!-- 2. *.action *.do 拦截以do action结尾的请求 肯定能使用 ERP-->
<!-- 3. / 拦截所有 (不包括jsp) (包含.js .png.css) 强烈建议使用-->
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
springmvc文件 dispatcher-serlvet.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:tx="http://www.springframework.org/schema/tx"
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-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-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-4.0.xsd">
<mvc:annotation-driven />
<!-- 开启注解扫描 这里扫描的是我的控制层包 用来扫描@Controller注解 -->
<context:component-scan base-package="CrudController">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!--扫描dao包下的注解-->
<context:component-scan base-package="dao">
</context:component-scan>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
@controller
@Controller("MyController")
@RequestMapping(value="/Student")
public class MyController {
@RequestMapping(value ="xx", method = RequestMethod.GET)
public ModelAndView postform() {
ModelAndView mv = new ModelAndView("postform");
return mv;
}
@RequestMapping(value = "test")
public ModelAndView test() {
ModelAndView mv = new ModelAndView();
mv.setViewName("index");
return mv;
}
}
index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<html>
<body>
<h2>Hello World!</h2>
<a href ="Student/xx" method="get">aaa</a>
</body>
</html>
点击aaa跳转 到postform.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>test</title>
</head>
<body>
这是跳转的测试文件!
这是跳转的测试文件!
这是跳转的测试文件!
这是跳转的测试文件!
</body>
</html>
还是404啊啊啊啊啊啊
明天计划的事情:
解决问题
评论