spring SpringWebXMLServletMVC
程序员文章站
2022-05-29 23:17:52
...
今天又看了spring.pdf的mvc介绍,清晰多了。贴几个主要配置文件。
web.xml
Config.xml
注意validator的配置。
web.xml
<?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <servlet> <servlet-name>Dispatcher</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/Config.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>Dispatcher</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> </web-app>
Config.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <!--Definition of View Resolver --> <bean id="viewResolver" ⑴ class="org.springframework.web.servlet.view.InternalResou rceViewResolver"> <property name="viewClass"> ⑵ <value> org.springframework.web.servlet.view.JstlView </value> </property> <property name="prefix"> ⑶ <value> /WEB-INF/view/ </value> </property> <property name="suffix"> ⑷ <value>.jsp</value> </property> </bean> <!--Request Mapping --> <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUr lHandlerMapping"> <property name="mappings"> <props> <prop key="/login.do">LoginAction</prop> </props> </property> </bean> <!---Action Definition--> <bean id="LoginAction" class="net.xiaxin.action.LoginAction"> <property name="commandClass"> <value>net.xiaxin.action.LoginInfo</value> </property> <property name="fail_view"> <value>loginfail</value> </property> <property name="success_view"> <value>main</value> </property> </bean> <bean id="RegisterValidator" class="net.xiaxin.validator.RegisterValidator"/> <bean id="RegisterAction" class="net.xiaxin.action.RegisterAction"> <property name="commandClass"> <value>net.xiaxin.reqbean.RegisterInfo</value> </property> <property name="validator"> <ref local="RegisterValidator"/> </property> <property name="formView"> <value>register</value> </property> <property name="successView"> <value>RegisterSuccess</value> </property> </bean> <!--Request Mapping --> <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUr lHandlerMapping"> <property name="mappings"> <props> <prop key="/register.do">RegisterAction</prop> </props> </property> </bean> </beans>
注意validator的配置。
下一篇: 关于富文本框KindEditor的使用
推荐阅读