最新版Struts2+Hibernate+Spring整合
目前为止三大框架最新版本是:
struts2.3.16.1
hibernate4.3.4
spring4.0.2
其中struts2和hibernate的下载方式比较简单,但是spring下载有点麻烦,可以直接复制下面链接下载最新版spring
http://repo.springsource.org/libs-release-local/org/springframework/spring/4.0.2.RELEASE/spring-framework-4.0.2.RELEASE-dist.zip
框架 | 版本 | 所需jar包 |
Struts2 | 2.3.16.1 | |
Hibernate | 4.3.4 | |
spring | 4.0.2 | |
其它 | 无 | |
二. 创建一张表
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_name` varchar(20) DEFAULT NULL,
`password` varchar(20) DEFAULT NULL,
`address` varchar(100) DEFAULT NULL,
`phone_number` varchar(20) DEFAULT NULL,
`create_time` datetime DEFAULT NULL,
`update_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULTCHARSET=utf8;
并插入一条数据INSERT INTO `user` VALUES ('1', 'test','test', 'test', 'test', '2014-03-29 00:48:14', '2014-03-29 00:48:17');
三. 先看下myeclipse的目录结构
四. 配置文件
1. web.xml
- <?xmlversion="1.0"encoding="UTF-8"?>
- <web-appversion="3.0"
- 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_3_0.xsd">
- <display-name></display-name>
- <!--添加对spring的支持-->
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath:applicationContext.xml</param-value>
- </context-param>
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <!--添加对struts2的支持-->
- <filter>
- <filter-name>struts2</filter-name>
- <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
- </filter>
- <!--当hibernate+spring配合使用的时候,如果设置了lazy=true,那么在读取数据的时候,当读取了父数据后,
- hibernate会自动关闭session,这样,当要使用子数据的时候,系统会抛出lazyinit的错误,
- 这时就需要使用spring提供的OpenSessionInViewFilter,OpenSessionInViewFilter主要是保持Session状态
- 知道request将全部页面发送到客户端,这样就可以解决延迟加载带来的问题-->
- <filter>
- <filter-name>openSessionInViewFilter</filter-name>
- <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
- <init-param>
- <param-name>singleSession</param-name>
- <param-value>true</param-value>
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <filter-mapping>
- <filter-name>openSessionInViewFilter</filter-name>
- <url-pattern>*.do,*.action</url-pattern>
- </filter-mapping>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- </web-app>
2. applicationContext.xml
- <?xmlversion="1.0"encoding="UTF-8"?>
- <beansxmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:p="http://www.springframework.org/schema/p"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:jee="http://www.springframework.org/schema/jee"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="
- http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-4.0.xsd
- http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.0.xsd
- http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-4.0.xsd
- http://www.springframework.org/schema/jeehttp://www.springframework.org/schema/jee/spring-jee-4.0.xsd
- http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
- <!--加载数据库属性配置文件-->
- <context:property-placeholderlocation="classpath:db.properties"/>
- <!--数据库连接池c3p0配置-->
- <beanid="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSource"
- destroy-method="close">
- <propertyname="jdbcUrl"value="${db.url}"></property>
- <propertyname="driverClass"value="${db.driverClassName}"></property>
- <propertyname="user"value="${db.username}"></property>
- <propertyname="password"value="${db.password}"></property>
- <propertyname="maxPoolSize"value="40"></property>
- <propertyname="minPoolSize"value="1"></property>
- <propertyname="initialPoolSize"value="1"></property>
- <propertyname="maxIdleTime"value="20"></property>
- </bean>
- <!--session工厂-->
- <beanid="sessionFactory"
- class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
- <propertyname="dataSource">
- <refbean="dataSource"/>
- </property>
- <propertyname="configLocation"value="classpath:hibernate.cfg.xml"/>
- <!--自动扫描注解方式配置的hibernate类文件-->
- <propertyname="packagesToScan">
- <list>
- <value>com.bufoon.entity</value>
- </list>
- </property>
- </bean>
- <!--配置事务管理器-->
- <beanid="transactionManager"
- class="org.springframework.orm.hibernate4.HibernateTransactionManager">
- <propertyname="sessionFactory"ref="sessionFactory"/>
- </bean>
- <!--配置事务通知属性-->
- <tx:adviceid="txAdvice"transaction-manager="transactionManager">
- <!--定义事务传播属性-->
- <tx:attributes>
- <tx:methodname="insert*"propagation="REQUIRED"/>
- <tx:methodname="update*"propagation="REQUIRED"/>
- <tx:methodname="edit*"propagation="REQUIRED"/>
- <tx:methodname="save*"propagation="REQUIRED"/>
- <tx:methodname="add*"propagation="REQUIRED"/>
- <tx:methodname="new*"propagation="REQUIRED"/>
- <tx:methodname="set*"propagation="REQUIRED"/>
- <tx:methodname="remove*"propagation="REQUIRED"/>
- <tx:methodname="delete*"propagation="REQUIRED"/>
- <tx:methodname="change*"propagation="REQUIRED"/>
- <tx:methodname="get*"propagation="REQUIRED"read-only="true"/>
- <tx:methodname="find*"propagation="REQUIRED"read-only="true"/>
- <tx:methodname="load*"propagation="REQUIRED"read-only="true"/>
- <tx:methodname="*"propagation="REQUIRED"read-only="true"/>
- </tx:attributes>
- </tx:advice>
- <!--应用普通类获取bean
- <beanid="appContext"class="com.soanl.util.tool.ApplicationUtil"/>-->
- <!--配置事务切面-->
- <aop:config>
- <aop:pointcutid="serviceOperation"
- expression="execution(*com.bufoon.service..*.*(..))"/>
- <aop:advisoradvice-ref="txAdvice"pointcut-ref="serviceOperation"/>
- </aop:config>
- <!--自动加载构建bean-->
- <context:component-scanbase-package="com.bufoon"/>
- </beans>
3. db.properties
- db.driverClassName=com.mysql.jdbc.Driver
- db.url=jdbc:mysql://localhost:3306/test
- db.username=root
- db.password=root
4. hibernate.cfg.xml
- <?xmlversion='1.0'encoding='UTF-8'?>
- <!DOCTYPEhibernate-configurationPUBLIC
- "-//Hibernate/HibernateConfigurationDTD3.0//EN"
- "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <propertyname="dialect">org.hibernate.dialect.MySQLDialect</property>
- <propertyname="jdbc.batch_size">20</property>
- <propertyname="connection.autocommit">true</property>
- <!--显示sql语句-->
- <propertyname="show_sql">true</property>
- <propertyname="connection.useUnicode">true</property>
- <propertyname="connection.characterEncoding">UTF-8</property>
- <!--缓存设置-->
- <propertyname="cache.provider_configuration_file_resource_path">/ehcache.xml</property>
- <propertyname="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
- <propertyname="cache.use_query_cache">true</property>
- </session-factory>
- </hibernate-configuration>
5. struts.xml
- <?xmlversion="1.0"encoding="UTF-8"?>
- <!DOCTYPEstrutsPUBLIC
- "-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.3//EN"
- "http://struts.apache.org/dtds/struts-2.3.dtd">
- <struts>
- <constantname="struts.i18n.encoding"value="UTF-8"/>
- <constantname="struts.action.extension"value="action"/>
- <constantname="struts.serve.static.browserCache"value="false"/>
- <packagename="s2sh"namespace="/user"extends="struts-default">
- <actionname="login"method="login"class="com.bufoon.action.LoginAction">
- <resultname="success">/success.jsp</result>
- <resultname="error">/login.jsp</result>
- </action>
- </package>
- </struts>
6. ehcache.xml (可以到下载的hibernate文件目录(hibernate-release-4.3.4.Final\hibernate-release-4.3.4.Final\project\etc)下找
五. JAVA类
1.BaseDAO.java(网上找的一个)
- packagecom.bufoon.dao;
- importjava.io.Serializable;
- importjava.util.List;
- /**
- *基础数据库操作类
- *
- *@authorss
- *
- */
- publicinterfaceBaseDAO<T>{
- /**
- *保存一个对象
- *
- *@paramo
- *@return
- */
- publicSerializablesave(To);
- /**
- *删除一个对象
- *
- *@paramo
- */
- publicvoiddelete(To);
- /**
- *更新一个对象
- *
- *@paramo
- */
- publicvoidupdate(To);
- /**
- *保存或更新对象
- *
- *@paramo
- */
- publicvoidsaveOrUpdate(To);
- /**
- *查询
- *
- *@paramhql
- *@return
- */
- publicList<T>find(Stringhql);
- /**
- *查询集合
- *
- *@paramhql
- *@paramparam
- *@return
- */
- publicList<T>find(Stringhql,Object[]param);
- /**
- *查询集合
- *
- *@paramhql
- *@paramparam
- *@return
- */
- publicList<T>find(Stringhql,List<Object>param);
- /**
- *查询集合(带分页)
- *
- *@paramhql
- *@paramparam
- *@parampage
- *查询第几页
- *@paramrows
- *每页显示几条记录
- *@return
- */
- publicList<T>find(Stringhql,Object[]param,Integerpage,Integerrows);
- /**
- *查询集合(带分页)
- *
- *@paramhql
- *@paramparam
- *@parampage
- *@paramrows
- *@return
- */
- publicList<T>find(Stringhql,List<Object>param,Integerpage,Integerrows);
- /**
- *获得一个对象
- *
- *@paramc
- *对象类型
- *@paramid
- *@returnObject
- */
- publicTget(Class<T>c,Serializableid);
- /**
- *获得一个对象
- *
- *@paramhql
- *@paramparam
- *@returnObject
- */
- publicTget(Stringhql,Object[]param);
- /**
- *获得一个对象
- *
- *@paramhql
- *@paramparam
- *@return
- */
- publicTget(Stringhql,List<Object>param);
- /**
- *selectcount(*)from类
- *
- *@paramhql
- *@return
- */
- publicLongcount(Stringhql);
- /**
- *selectcount(*)from类
- *
- *@paramhql
- *@paramparam
- *@return
- */
- publicLongcount(Stringhql,Object[]param);
- /**
- *selectcount(*)from类
- *
- *@paramhql
- *@paramparam
- *@return
- */
- publicLongcount(Stringhql,List<Object>param);
- /**
- *执行HQL语句
- *
- *@paramhql
- *@return响应数目
- */
- publicIntegerexecuteHql(Stringhql);
- /**
- *执行HQL语句
- *
- *@paramhql
- *@paramparam
- *@return响应数目
- */
- publicIntegerexecuteHql(Stringhql,Object[]param);
- /**
- *执行HQL语句
- *
- *@paramhql
- *@paramparam
- *@return
- */
- publicIntegerexecuteHql(Stringhql,List<Object>param);
- }
2. BaseDAOImpl.java
- packagecom.bufoon.dao.impl;
- importjava.io.Serializable;
- importjava.util.List;
- importorg.hibernate.Query;
- importorg.hibernate.Session;
- importorg.hibernate.SessionFactory;
- importorg.springframework.beans.factory.annotation.Autowired;
- importorg.springframework.stereotype.Repository;
- importcom.bufoon.dao.BaseDAO;
- @Repository("baseDAO")
- @SuppressWarnings("all")
- publicclassBaseDAOImpl<T>implementsBaseDAO<T>{
- privateSessionFactorysessionFactory;
- publicSessionFactorygetSessionFactory(){
- returnsessionFactory;
- }
- @Autowired
- publicvoidsetSessionFactory(SessionFactorysessionFactory){
- this.sessionFactory=sessionFactory;
- }
- privateSessiongetCurrentSession(){
- returnsessionFactory.getCurrentSession();
- }
- publicSerializablesave(To){
- returnthis.getCurrentSession().save(o);
- }
- publicvoiddelete(To){
- this.getCurrentSession().delete(o);
- }
- publicvoidupdate(To){
- this.getCurrentSession().update(o);
- }
- publicvoidsaveOrUpdate(To){
- this.getCurrentSession().saveOrUpdate(o);
- }
- publicList<T>find(Stringhql){
- returnthis.getCurrentSession().createQuery(hql).list();
- }
- publicList<T>find(Stringhql,Object[]param){
- Queryq=this.getCurrentSession().createQuery(hql);
- if(param!=null&¶m.length>0){
- for(inti=0;i<param.length;i++){
- q.setParameter(i,param[i]);
- }
- }
- returnq.list();
- }
- publicList<T>find(Stringhql,List<Object>param){
- Queryq=this.getCurrentSession().createQuery(hql);
- if(param!=null&¶m.size()>0){
- for(inti=0;i<param.size();i++){
- q.setParameter(i,param.get(i));
- }
- }
- returnq.list();
- }
- publicList<T>find(Stringhql,Object[]param,Integerpage,Integerrows){
- if(page==null||page<1){
- page=1;
- }
- if(rows==null||rows<1){
- rows=10;
- }
- Queryq=this.getCurrentSession().createQuery(hql);
- if(param!=null&¶m.length>0){
- for(inti=0;i<param.length;i++){
- q.setParameter(i,param[i]);
- }
- }
- returnq.setFirstResult((page-1)*rows).setMaxResults(rows).list();
- }
- publicList<T>find(Stringhql,List<Object>param,Integerpage,Integerrows){
- if(page==null||page<1){
- page=1;
- }
- if(rows==null||rows<1){
- rows=10;
- }
- Queryq=this.getCurrentSession().createQuery(hql);
- if(param!=null&¶m.size()>0){
- for(inti=0;i<param.size();i++){
- q.setParameter(i,param.get(i));
- }
- }
- returnq.setFirstResult((page-1)*rows).setMaxResults(rows).list();
- }
- publicTget(Class<T>c,Serializableid){
- return(T)this.getCurrentSession().get(c,id);
- }
- publicTget(Stringhql,Object[]param){
- List<T>l=this.find(hql,param);
- if(l!=null&&l.size()>0){
- returnl.get(0);
- }else{
- returnnull;
- }
- }
- publicTget(Stringhql,List<Object>param){
- List<T>l=this.find(hql,param);
- if(l!=null&&l.size()>0){
- returnl.get(0);
- }else{
- returnnull;
- }
- }
- publicLongcount(Stringhql){
- return(Long)this.getCurrentSession().createQuery(hql).uniqueResult();
- }
- publicLongcount(Stringhql,Object[]param){
- Queryq=this.getCurrentSession().createQuery(hql);
- if(param!=null&¶m.length>0){
- for(inti=0;i<param.length;i++){
- q.setParameter(i,param[i]);
- }
- }
- return(Long)q.uniqueResult();
- }
- publicLongcount(Stringhql,List<Object>param){
- Queryq=this.getCurrentSession().createQuery(hql);
- if(param!=null&¶m.size()>0){
- for(inti=0;i<param.size();i++){
- q.setParameter(i,param.get(i));
- }
- }
- return(Long)q.uniqueResult();
- }
- publicIntegerexecuteHql(Stringhql){
- returnthis.getCurrentSession().createQuery(hql).executeUpdate();
- }
- publicIntegerexecuteHql(Stringhql,Object[]param){
- Queryq=this.getCurrentSession().createQuery(hql);
- if(param!=null&¶m.length>0){
- for(inti=0;i<param.length;i++){
- q.setParameter(i,param[i]);
- }
- }
- returnq.executeUpdate();
- }
- publicIntegerexecuteHql(Stringhql,List<Object>param){
- Queryq=this.getCurrentSession().createQuery(hql);
- if(param!=null&¶m.size()>0){
- for(inti=0;i<param.size();i++){
- q.setParameter(i,param.get(i));
- }
- }
- returnq.executeUpdate();
- }
- }
3. UserService.java
- packagecom.bufoon.service.user;
- importjava.util.List;
- importcom.bufoon.entity.User;
- publicinterfaceUserService{
- publicvoidsaveUser(Useruser);
- publicvoidupdateUser(Useruser);
- publicUserfindUserById(intid);
- publicvoiddeleteUser(Useruser);
- publicList<User>findAllList();
- publicUserfindUserByNameAndPassword(Stringusername,Stringpassword);
- }
4. UserServiceImpl.java
- packagecom.bufoon.service.user.impl;
- importjava.util.List;
- importjavax.annotation.Resource;
- importorg.springframework.stereotype.Service;
- importcom.bufoon.dao.BaseDAO;
- importcom.bufoon.entity.User;
- importcom.bufoon.service.user.UserService;
- @Service("userService")
- publicclassUserServiceImplimplementsUserService{
- @Resource
- privateBaseDAO<User>baseDAO;
- @Override
- publicvoidsaveUser(Useruser){
- baseDAO.save(user);
- }
- @Override
- publicvoidupdateUser(Useruser){
- baseDAO.update(user);
- }
- @Override
- publicUserfindUserById(intid){
- returnbaseDAO.get(User.class,id);
- }
- @Override
- publicvoiddeleteUser(Useruser){
- baseDAO.delete(user);
- }
- @Override
- publicList<User>findAllList(){
- returnbaseDAO.find("fromUseruorderbyu.createTime");
- }
- @Override
- publicUserfindUserByNameAndPassword(Stringusername,Stringpassword){
- returnbaseDAO.get("fromUseruwhereu.userName=?andu.password=?",newObject[]{username,password});
- }
- }
5. LoginAction
- packagecom.bufoon.action;
- importjavax.annotation.Resource;
- importjavax.servlet.http.HttpServletRequest;
- importorg.apache.struts2.ServletActionContext;
- importorg.springframework.stereotype.Controller;
- importcom.bufoon.entity.User;
- importcom.bufoon.service.user.UserService;
- importcom.opensymphony.xwork2.ActionSupport;
- @Controller
- publicclassLoginActionextendsActionSupport{
- privatestaticfinallongserialVersionUID=1L;
- @Resource
- privateUserServiceuserService;
- privateStringusername;
- privateStringpassword;
- publicStringlogin(){
- HttpServletRequestrequest=ServletActionContext.getRequest();
- Useruser=userService.findUserByNameAndPassword(username,password);
- if(user!=null){
- request.setAttribute("username",username);
- returnSUCCESS;
- }else{
- returnERROR;
- }
- }
- publicStringgetUsername(){
- returnusername;
- }
- publicvoidsetUsername(Stringusername){
- this.username=username;
- }
- publicStringgetPassword(){
- returnpassword;
- }
- publicvoidsetPassword(Stringpassword){
- this.password=password;
- }
- }
6. Util.java
- packagecom.bufoon.util;
- importjava.io.PrintWriter;
- importjava.io.StringWriter;
- importjava.security.MessageDigest;
- importorg.springframework.context.ApplicationContext;
- importorg.springframework.context.support.ClassPathXmlApplicationContext;
- importcom.bufoon.entity.User;
- importcom.bufoon.service.user.UserService;
- importsun.misc.BASE64Encoder;
- /**
- *通用工具类
- */
- publicclassUtil{
- /**
- *对字符串进行MD5加密
- *
- *@paramstr
- *@returnString
- */
- publicstaticStringmd5Encryption(Stringstr){
- StringnewStr=null;
- try{
- MessageDigestmd5=MessageDigest.getInstance("MD5");
- BASE64Encoderbase=newBASE64Encoder();
- newStr=base.encode(md5.digest(str.getBytes("UTF-8")));
- }catch(Exceptione){
- e.printStackTrace();
- }
- returnnewStr;
- }
- /**
- *判断字符串是否为空
- *
- *@paramstr
- *字符串
- *@returntrue:为空;false:非空
- */
- publicstaticbooleanisNull(Stringstr){
- if(str!=null&&!str.trim().equals("")){
- returnfalse;
- }else{
- returntrue;
- }
- }
- }
- packagecom.bufoon.entity;
- importjava.util.Date;
- importjavax.persistence.Column;
- importjavax.persistence.Entity;
- importjavax.persistence.GeneratedValue;
- importjavax.persistence.Id;
- importjavax.persistence.Temporal;
- importjavax.persistence.TemporalType;
- importorg.hibernate.annotations.GenericGenerator;
- @Entity
- publicclassUser{
- privateIntegerid;
- privateStringuserName;
- privateStringpassword;
- privateStringaddress;
- privateStringphoneNumber;
- privateDatecreateTime;
- privateDateupdateTime;
- @Id
- @GenericGenerator(name="generator",strategy="increment")
- @GeneratedValue(generator="generator")
- @Column(name="ID",length=11)
- publicIntegergetId(){
- returnid;
- }
- publicvoidsetId(Integerid){
- this.id=id;
- }
- @Column(name="user_name",length=20)
- publicStringgetUserName(){
- returnuserName;
- }
- publicvoidsetUserName(StringuserName){
- this.userName=userName;
- }
- @Column(name="password",length=20)
- publicStringgetPassword(){
- returnpassword;
- }
- publicvoidsetPassword(Stringpassword){
- this.password=password;
- }
- @Column(name="address",length=100)
- publicStringgetAddress(){
- returnaddress;
- }
- publicvoidsetAddress(Stringaddress){
- this.address=address;
- }
- @Column(name="phone_number",length=20)
- publicStringgetPhoneNumber(){
- returnphoneNumber;
- }
- publicvoidsetPhoneNumber(StringphoneNumber){
- this.phoneNumber=phoneNumber;
- }
- @Temporal(TemporalType.TIMESTAMP)
- @Column(name="create_time")
- publicDategetCreateTime(){
- returncreateTime;
- }
- publicvoidsetCreateTime(DatecreateTime){
- this.createTime=createTime;
- }
- @Temporal(TemporalType.TIMESTAMP)
- @Column(name="update_time")
- publicDategetUpdateTime(){
- returnupdateTime;
- }
- publicvoidsetUpdateTime(DateupdateTime){
- this.updateTime=updateTime;
- }
- }
六. JSP文件
1. login.jsp
- <%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"%>
- <%
- Stringpath=request.getContextPath();
- StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
- %>
- <!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
- <html>
- <head>
- <basehref="<%=basePath%>">
- <title>MyJSP'index.jsp'startingpage</title>
- <metahttp-equiv="pragma"content="no-cache">
- <metahttp-equiv="cache-control"content="no-cache">
- <metahttp-equiv="expires"content="0">
- <metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
- <metahttp-equiv="description"content="Thisismypage">
- <!--
- <linkrel="stylesheet"type="text/css"href="styles.css">
- -->
- </head>
- <body>
- <formaction="${pageContext.request.contextPath}/user/login.action"method="post">
- username:<inputtype="text"name="username"/><br/>
- password:<inputtype="password"name="password"/><br/>
- <inputtype="submit"value="login"/><inputtype="reset"value="reset"/>
- </form>
- </body>
- </html>
2. success.jsp
- <%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"%>
- <%
- Stringpath=request.getContextPath();
- StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
- %>
- <!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
- <html>
- <head>
- <basehref="<%=basePath%>">
- <title>MyJSP'index.jsp'startingpage</title>
- <metahttp-equiv="pragma"content="no-cache">
- <metahttp-equiv="cache-control"content="no-cache">
- <metahttp-equiv="expires"content="0">
- <metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
- <metahttp-equiv="description"content="Thisismypage">
- <!--
- <linkrel="stylesheet"type="text/css"href="styles.css">
- -->
- </head>
- <body>
- 欢迎您:{username}!
- </body>
- </html>
附上下载地址:http://download.csdn.net/detail/soanl/7158959
================================================================ENDING========================================================
2014-03-29
布丰(bufoon)
更正(struts.xml文件)感谢u013506859提出