创建一个SpringMVC小项目
来源:互联网 发布:怎么加入淘宝全球购 编辑:程序博客网 时间:2024/05/17 05:13
/springMVC/WebContent/WEB-INF/lib/commons-logging-1.1.3.jar
/springMVC/WebContent/WEB-INF/lib/spring-aop-4.3.7.RELEASE.jar
/springMVC/WebContent/WEB-INF/lib/spring-beans-4.3.7.RELEASE.jar
/springMVC/WebContent/WEB-INF/lib/spring-context-4.3.7.RELEASE.jar
/springMVC/WebContent/WEB-INF/lib/spring-core-4.3.7.RELEASE.jar
/springMVC/WebContent/WEB-INF/lib/spring-expression-4.3.7.RELEASE.jar
/springMVC/WebContent/WEB-INF/lib/spring-web-4.3.7.RELEASE.jar
/springMVC/WebContent/WEB-INF/lib/spring-webmvc-4.3.7.RELEASE.jar
2 配置web.xml文件
<!-- web.xml配置核心springMVC的Servlet分发器 The front controller of this Spring Web application, responsible for handling all application requests --><servlet><servlet-name>springDispatcherServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:springmvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><!-- Map all requests to the DispatcherServlet for handling --><servlet-mapping><servlet-name>springDispatcherServlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping> <!--这里是区分method的过滤器 --> <filter> <filter-name>methodFilter</filter-name> <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> </filter> <filter-mapping> <filter-name>methodFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
这里需要注意:
Servlet分发器的url-pattern是/,而不是/*。原因在于优先级 /* > .jsp > / ,所以如果url-pattern是/*,则任意请求都要进入Servlet分发器,而请求可能只是访问index.jsp页面,不需要经过Servlet分发器处理。
如果没有用参数来说明springMVC配置文件的路径,采用默认配置的话,则默认路径是 /WEB-INF/<servlet-name>-servlet.xml
例如在WEB-INF文件夹下面有个springDispatcherServlet-servlet.xml,这样也可以找到。
3 配合springMVC核心文件
<?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/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd"><context:component-scan base-package="com.anseon.controller"/><!--配置视图解析器 --><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/views/"/><property name="suffix" value=".jsp"/></bean></beans>
4 在代码中配置Controller的RequestMapping,请求路径的映射
@Controller@RequestMapping("/springmvc")public class Hello { private static final String SUCCESS = "success"; /** * 最终的视图: * prefix+returnValue+suffix * /WEB-INF/views/success.jsp */ @RequestMapping("/hello") public String execute(){ System.out.println("execute"); return SUCCESS; }}
访问http://localhost:8080/springmvc01/index.jsp
然后执行操作之后返回的是/WEB-INF/views文件夹下的success.jsp页面。
问题:跳转到success.jsp页面的时候是重定向还是转发?
- 创建一个SpringMVC小项目
- 用maven+springMVC创建一个项目
- 创建一个SpringMVC + FreeMarket 的入门项目
- IDEA下创建一个Maven + SpringMVC项目
- 创建一个通讯录小项目代码
- 创建一个SpringBoot + springmvc + hibernateJPA + MyBatis的项目
- STS怎么创建一个springMVC的Maven项目
- 在IDEA中用maven来创建一个springMVC项目
- 创建一个简单的maven类型的springmvc项目
- maven创建springmvc项目
- 创建简单springMVC项目
- 创建SpringMVC项目
- maven 创建springmvc项目
- Maven 创建springMvc项目
- maven创建springmvc项目
- 创建简单SpringMVC项目
- springmvc项目创建
- 创建SpringMVC+Mybatis项目
- java ImageIO处理
- Jzoj4784 Map
- 习题4
- Node.js入门到企业Web开发中的应用
- 微信模板消息发送
- 创建一个SpringMVC小项目
- 电脑打字究竟对书写习惯产生了多大影响?
- Tablayout简单布局
- Game of Dice GYM101532E
- Curl超时设置
- 添加页面
- android ServerSocket 和 Socket使用简单讲解
- 插件实现三级联动
- AngularJS的添加信息判断+路由