博主采用的是eclipse+springmvc+jsp来做这一功能讲解。如控制器采用的是其他组件,原理一样,自己结合自己的实际环境来调整。
尊重原创,觉得有用多多推广,顺便给个赞。谢谢。
分三步:
第一,web.xml和applicationContext.xml的配置,如已掌握的童鞋,可自动忽略这节。
新建一个web工程,然后在src目录下新建一个applicationContext.xml文件
web.xm文件,源码在图片下方
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
springmvc
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:applicationContext.xml
1
springmvc
*.do
encodingfilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
encodingfilter
/*
/WEB-INF/index.jsp
404
/WEB-INF/404.jsp
applicationContext.xml文件
xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
class="org.apache.commons.dbcp.BasicDataSource">
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
整个工程目录如下:
项目引入jar包如下:这些是工程中用到的全部jar包,包括加解密,xml解析,springmvc等用到的全部jar包。如你的工程不需要则可以自行删除对应jar包。