SpringMVC程序简单实例
网络编程 2021-07-05 11:23www.168986.cn编程入门
这篇文章主要介绍了SpringMVC程序简单实例的相关资料,需要的朋友可以参考下
StringMVC程序简单实例
第一步:导入jar包
第二步,在WEB-INF文件夹下创建spring-servlet.xml文件。
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://.springframework./schema/beans" xmlns:xsi="http://.w3./2001/XMLSchema-instance" xmlns:p="http://.springframework./schema/p" xmlns:context="http://.springframework./schema/context" xmlns:aop="http://.springframework./schema/aop" xsi:schemaLocation="http://.springframework./schema/beans http://.springframework./schema/beans/spring-beans-3.0.xsd http://.springframework./schema/aop http://.springframework./schema/aop/spring-aop-3.0.xsd http://.springframework./schema/tx http://.springframework./schema/tx/spring-tx-3.0.xsd http://.springframework./schema/context http://.springframework./schema/context/spring-context-3.0.xsd"> <!-- 注册aop功能 --> <aop:aspectj-auroxy/> <!-- 自动扫面.springmvc目录及其子目录狼蚁网站SEO优化所有类文件,自动注入所有带注解的类 --> <context:ponent-scan base-package=".yxl.*" /> <!-- 处理请求response返回值,如下配置能正确返回字符串型返回值,如返回值为对象,则自动转为json --> <bean id="handleAdapter" class=".springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="messageConverters"> <list> <ref bean="mappingJacksonHttpMessageConverter" /><!-- json转换器 --> <ref bean="mappingStringHttpMessageConverter" /> </list> </property> </bean> <bean id="mappingJacksonHttpMessageConverter" class=".springframework.http.converter.json.MappingJacksonHttpMessageConverter" /> <bean id="mappingStringHttpMessageConverter" class=".springframework.http.converter.StringHttpMessageConverter" /> <!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 --> <bean id="viewResolver" class=".springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp"></property> <property name="order" value="1"></property> </bean> <!-- spring文件上传编码 --> <bean id="multipartResolver" class=".springframework.web.multipart.mons.CommonsMultipartResolver" p:defaultEncoding="utf-8" /> </beans>
第三步:在web.xml文件配置springmvc。
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://.w3./2001/XMLSchema-instance" xmlns="http://java.sun./xml/ns/javaee" xmlns:web="http://java.sun./xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun./xml/ns/javaee http://java.sun./xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>springmvc1</display-name> <wele-file-list> <wele-file>index.html</wele-file> <wele-file>index.htm</wele-file> <wele-file>index.jsp</wele-file> <wele-file>default.html</wele-file> <wele-file>default.htm</wele-file> <wele-file>default.jsp</wele-file> </wele-file-list> <!-- 设置编码 --> <filter> <filter-name>characterEncodingFilter</filter-name> <filter-class>.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <!-- 配置DispatchcerServlet --> <servlet> <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> <servlet-class>.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <!-- 配置Spring mvc下的配置文件的位置和名称 --> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring-servlet.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- 配置DispatchcerServlet 拦击路径'/'所有访问都拦截--> <servlet-mapping> <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
第四步:创建一个控制器。
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程