Sprign MVC MVCServletBeanSpringWeb
程序员文章站
2024-02-05 16:15:52
...
(1) index.htm n内容如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; CHARSET=utf8"/>
<title>Edgen test MVC: First page</title>
</head>
<body>
<form method="POST" action="login.do">
<p align="center">登录</p>
<br>用户名:
<input type="text" name="userName">
<br>密码:&&
<input type="password" name="password">
<p>
<input type="submit" value="提交" name="B1">
<input type="reset" value="重置" name="B2">
</p>
</form>
</body>
</html>
(2) Web.xml 内容如下:
<?xml version="1.0" encoding="GBK"?>
<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.sum.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/Dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
(3) Dispatcher-servlet.xml 内容如下:
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<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>
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/login.do">LoginAction</prop>
</props>
</property>
</bean>
<bean id="LoginAction"
class="net.zhanglong.edgen.action.LoginAction">
<property name="commandClass">
<value>net.zhanglong.edgen.action.LoginInfo</value>
</property>
<property name="fail_view">
<value>loginfail</value>
</property>
<property name="success_view">
<value>main</value>
</property>
</bean>
</beans>
(4) Tomcat 工程(也就是以Variable形式Import 了servlet-api.jar, jsper-runtime.jar, jsp-api.jar )
(5)其它jar: Import spring.jar, taglib.jar, log4j.jar, cglib.jar, commonds-xxxx.jar, 以Variable 形式Import进jstl-1.1.jar,否则报错:jstl相关类找不到
(6)有点怪! Spring.jar 必须:放在工程lib 或Tomcat/commom/lib 下, 或者以Variable 的形式import, 否则会报错:找不到 DispatcherServlet
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; CHARSET=utf8"/>
<title>Edgen test MVC: First page</title>
</head>
<body>
<form method="POST" action="login.do">
<p align="center">登录</p>
<br>用户名:
<input type="text" name="userName">
<br>密码:&&
<input type="password" name="password">
<p>
<input type="submit" value="提交" name="B1">
<input type="reset" value="重置" name="B2">
</p>
</form>
</body>
</html>
(2) Web.xml 内容如下:
<?xml version="1.0" encoding="GBK"?>
<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.sum.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/Dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
(3) Dispatcher-servlet.xml 内容如下:
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<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>
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/login.do">LoginAction</prop>
</props>
</property>
</bean>
<bean id="LoginAction"
class="net.zhanglong.edgen.action.LoginAction">
<property name="commandClass">
<value>net.zhanglong.edgen.action.LoginInfo</value>
</property>
<property name="fail_view">
<value>loginfail</value>
</property>
<property name="success_view">
<value>main</value>
</property>
</bean>
</beans>
(4) Tomcat 工程(也就是以Variable形式Import 了servlet-api.jar, jsper-runtime.jar, jsp-api.jar )
(5)其它jar: Import spring.jar, taglib.jar, log4j.jar, cglib.jar, commonds-xxxx.jar, 以Variable 形式Import进jstl-1.1.jar,否则报错:jstl相关类找不到
(6)有点怪! Spring.jar 必须:放在工程lib 或Tomcat/commom/lib 下, 或者以Variable 的形式import, 否则会报错:找不到 DispatcherServlet
推荐阅读
-
Sprign MVC MVCServletBeanSpringWeb
-
结构、表现、行为与MVC的关系 MVC数据结构AjaxJavaScriptWeb
-
ASP.NET MVC5&微信公众平台整合开发实战(响应式布局、JQuery Mobile,Windows Azure、微信核心开发) mvc
-
asp.net mvc处理css和js版本问题 博客分类: C#ASP.netASP.net MVC MVC
-
MVC学习之一_____实现列表及分页 博客分类: MVC4
-
MVC学习之二_____查看详情信息 博客分类: MVC4
-
MVC学习之一_____实现列表及分页 博客分类: MVC4
-
MVC学习之二_____查看详情信息 博客分类: MVC4
-
MVC学习之五_____删除记录 博客分类: MVC4
-
MVC4 官方入门教程(适合初学者)【转】 博客分类: MVC4 MVC4框架初学