注册 登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

码农

用最简单的办法解决问题,用最奇怪的办法创造BUG

 
 
 

日志

 
 

123  

2010-07-03 11:45:46|  分类: J2EE |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

struts2
freemarker-2.3.8.jar
struts2-core-2.0.14.jar
struts2-spring-plugin-2.0.14.jar
ognl-2.6.11.jar
xwork-2.0.7.jar


spring2.5
Spring2.0 AOP Libraries
Spring2.0 Core Libraries
Spring2.0 Persistence Core Libraries
Spring2.0 WEb Libraries


hibernate3
Hibernate 3.0 Core Libraries
hibernate 3.0 Advanced Support Libraries

src目录下创建struts.xml头文件引用
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
 "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
 "http://struts.apache.org/dtds/struts-2.0.dtd">

web.xml文件中引用
  <!-- 声明struts2过滤器 -->
  <filter>
   <filter-name>struts2</filter-name>
   <filter-class>
    org.apache.struts2.dispatcher.FilterDispatcher
   </filter-class>
  </filter>
 
  <filter-mapping>
   <filter-name>struts2</filter-name>
   <url-pattern>/*</url-pattern>
  </filter-mapping>
 
  <!-- 这里配置spring,servlet2.4以上版本可以使用spring监听器,2.3一下使用过滤器,这里使用监听器。监听器在web应用启动时启动,过滤器在web应用访问时启动 -->
  <listener>
   <listener-class>
    org.springframework.web.context.ContextLoaderListener
   </listener-class>
  </listener>
  <!--
  <context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath*:applicationContext*.xml</param-value>
  </context-param>

  -->
 
  <!-- 配置clearup filter -->
  <filter>
   <filter-name>struts-cleanup</filter-name>
   <filter-class>
    org.apache.struts2.dispatcher.ActionContextCleanUp
   </filter-class>
  </filter>
 
   <filter-mapping>
   <filter-name>struts-cleanup</filter-name>
   <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!-- 配置openSessionInViewFilter过滤器,处理SESSION关闭 -->
  <filter>
   <filter-name>lazyLoadingFilter</filter-name>
   <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
  </filter>
  <filter-mapping>
   <filter-name>lazyLoadingFilter</filter-name>
   <url-pattern>*.action</url-pattern>
  </filter-mapping>

DAO
package com.t.dao;

import java.util.List;

import com.t.bean.User;

public interface UserDao {

 //添加用户
 public void saveUser(User user);
 
 //删除用户
 public void deleteUser(User user);
 
 //修改用户
 public void updateUser(User user);
 
 //查找用户sql
 public List<User> findUserBySql(String sql);
 
 //通过ID查找用户
 public User findUserById(Integer id);
 
 //查找所有用户
 public List<User> findAllUser();
 
}

daoimpl
package com.t.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.t.bean.User;
import com.t.dao.UserDao;

public class UserDaoImpl extends HibernateDaoSupport implements UserDao{

 public void deleteUser(User user) {
  // TODO Auto-generated method stub
  this.getHibernateTemplate().delete(user);
 }

 @SuppressWarnings("unchecked")
 public List<User> findAllUser() {
  // TODO Auto-generated method stub
  List<User> ul = this.getHibernateTemplate().find("from user order by user.id");
  return ul;
 }

 @SuppressWarnings("unchecked")
 public User findUserById(Integer id) {
  // TODO Auto-generated method stub
  List<User> ul = this.getHibernateTemplate().find("from user where user.id=?",id);
  if (ul !=null && ul.size() >= 1 ){
   return (User)ul.get(0);
  }
  return null;
 }

 @SuppressWarnings("unchecked")
 public List<User> findUserBySql(String sql) {
  // TODO Auto-generated method stub
  List<User> ul = this.getHibernateTemplate().find("from user order by user.id");
  return ul;
 }

 public void saveUser(User user) {
  // TODO Auto-generated method stub
  this.getHibernateTemplate().save(user);
 }

 public void updateUser(User user) {
  // TODO Auto-generated method stub
  this.getHibernateTemplate().update(user);
 }

}

service
package com.t.service;

import java.util.List;

import com.t.bean.User;

public interface UserService {
 
 //查询数据BYSQL
 public List<User> findUserBySql(String sql);
 //修改数据
 public String updateUser(User user);
 //添加数据
 public String saveUser(User user);
 //删除数据
 public String deleteUser(Integer id);
 //查询数据BYID
 public User findUserById(Integer id);
 //查询所有数据
 public List<User> findAllUser();

}


service impl

package com.t.service.impl;

import java.util.List;

import com.t.bean.User;
import com.t.dao.UserDao;
import com.t.service.UserService;

public class UserServiceImpl implements UserService {

 private UserDao userDao;

 public UserDao getUserDao() {
  return userDao;
 }

 public void setUserDao(UserDao userDao) {
  this.userDao = userDao;
 }

 public String deleteUser(Integer id) {
  // TODO Auto-generated method stub
  try {
   this.getUserDao().deleteUser(this.getUserDao().findUserById(id));
   return "操作失败!";
  } catch (Exception e) {
   return "操作失败!";
  }
 }

 public List<User> findAllUser() {
  // TODO Auto-generated method stub
  return this.getUserDao().findAllUser();
 }

 public User findUserById(Integer id) {
  // TODO Auto-generated method stub
  return this.getUserDao().findUserById(id);
 }

 public List<User> findUserBySql(String sql) {
  // TODO Auto-generated method stub
  return this.getUserDao().findUserBySql(sql);
 }

 public String saveUser(User user) {
  // TODO Auto-generated method stub
  try {
   this.getUserDao().saveUser(user);
   return "操作成功!";
  } catch (Exception e) {
   return "操作失败!";
  }
 }

 public String updateUser(User user) {
  // TODO Auto-generated method stub
  try {
   this.getUserDao().updateUser(user);
   return "操作成功!";
  } catch (Exception e) {
   return "操作失败!";
  }
 }
}


applicationContext
<?xml version="1.0" encoding="UTF-8"?>
<beans
 xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

 <bean id="databaseSource"
  class="org.apache.commons.dbcp.BasicDataSource">
  <property name="driverClassName"
   value="com.microsoft.sqlserver.jdbc.SQLServerDriver">
  </property>
  <property name="url"
   value="jdbc:sqlserver://localhost:1433;database=db_cate">
  </property>
  <property name="username" value="sa"></property>
  <property name="password" value="sa"></property>
  <property name="defaultAutoCommit" value="true"></property>
 </bean>
 <bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
  destroy-method="close">
  <property name="dataSource">
   <ref bean="databaseSource" />
  </property>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">
     org.hibernate.dialect.SQLServerDialect
    </prop>
    <prop key="hibernate.show_sql">true</prop>
   </props>
  </property>
  <property name="mappingResources">
   <list>
    <value>
     com/t/bean/User.hbm.xml
    </value>
    
   </list>
  </property>
 </bean>
 
 <!-- userdao -->
 <bean id="UserDao" class="com.t.dao.impl.UserDaoImpl" scope="singleton">
  <property name="sessionFactory">
   <ref bean="sessionFactory"/>
  </property>
 </bean>
 
 <!-- userService -->
 <bean id="UserService" class="com.t.service.impl.UserServiceImpl">
  <property name="userDao">
   <ref bean="UserDao"/>
  </property>
 </bean>
 
 <!-- useraction -->
 <bean id="UserAction" class="com.t.action.UserAction" scope="prototype">
  <property name="userService">
   <ref bean="UserService"/>
  </property>
 </bean>


</beans>

struts
 
 <struts>
 <!-- 打开开发模式 -->
 <!-- <constant name="struts.devMode" value="true" /> -->
 <!-- STRUTS2 标签配置 -->
 <package name="user" extends="struts-default" namespace="/">
  <action name="*_*" class="{1}" method="{2}">
   <result name="success">
    /index.jsp
   </result>
   <result name="updateForm">/updateform.jsp</result>
  </action>
  

 </package>
 


<%@ taglib prefix="s" uri="/struts-tags"%>
<s:iterator value="#request.list" id="cateMember">
     <tr>
      <td height="38" align="center">
       <s:property value="#cateMember.cateMemberId" />
      </td>
      <td height="38" align="center">
       <s:property value="#cateMember.cateMemberUsername" />
      </td>
      <td height="38" align="center">
       <s:property value="#cateMember.cateMemberTime" />
      </td>
      <td height="38" align="center">
       <s:property value="#cateMember.cateMemberAudit" />
      </td>
      <td height="38" align="center">
       <font> <a
        href="struts2/Admin/Admin_CateMemberAction_UpdateForm?cateMember.cateMemberId=<s:property value="#cateMember.cateMemberId" />">修改</a>
        &nbsp;&nbsp;&nbsp;&nbsp; <a
        href="struts2/Admin/Admin_CateMemberAction_Del?cateMember.cateMemberId=<s:property value="#cateMember.cateMemberId" />">删除</a>
       </font>
      </td>
     </tr>
    </s:iterator>

<s:form action="Admin/Admin_CateListTypeAction_Update">
   <s:hidden name="cateListType.cateListTypeId" value="%{cateListType.cateListTypeId}"/>
   <s:text name="%{getText('cateTypeName')}"/>:
   <s:textfield name="cateListType.cateListTypeName" value="%{cateListType.cateListTypeName}" theme="simple"></s:textfield>
   <br/>
   <s:text name="%{getText('cateTypeFollowId')}"/>:
   <s:select list="#request.list" listKey="cateListTypeId" listValue="cateListTypeName" headerKey="0" headerValue="--请选择--"  name="cateListType.cateListTypeFollowId" theme="simple"/>
   <br/>
   <s:submit type="submit" value="%{getText('update')}" theme="simple"/>    <s:reset value="%{getText('reset')}" theme="simple"/>
 
  </s:form>


<s:form action="Admin_CateMemberAction_Update" method="post">
   <table align="center" width="50%" style="border: 1px solid #3399ff">
    <tr>
     <td height="47" colspan="2" align="center">
      添加会员
     </td>
    </tr>
    <input type="hidden" name="cateMember.cateMemberId"
     value="${requestScope.cateMember.cateMemberId}">
    <tr>
     <td height="28" align="right" bgcolor="#3399ff">
      <font color="#FFFFFF">用户名:</font>
     </td>
     <td height="28">
      <input type="text" name="cateMember.cateMemberUsername"
       value="${cateMember.cateMemberUsername}">
     </td>
    </tr>
    <tr>
     <td height="27" align="right" bgcolor="#3399ff">
      <font color="#FFFFFF">密码:</font>
     </td>
     <td height="27">
      <input type="password" name="cateMember.cateMemberPassword"
       value="${cateMember.cateMemberPassword}">
     </td>
    </tr>
    <tr>
     <td height="27" align="right" bgcolor="#3399ff">
      <font color="#FFFFFF">确认密码:</font>
     </td>
     <td height="27">
      <input type="password" name="pass"
       value="${cateMember.cateMemberPassword}">
     </td>
    </tr>
    <tr>
     <td height="30" align="right" bgcolor="#3399ff">
      <font color="#FFFFFF">身份证号:</font>
     </td>
     <td height="30">
      <input type="text" name="cateMember.cateMemberIdnum"
       value="${cateMember.cateMemberIdnum}">
     </td>
    </tr>
    <tr>
     <td height="28" align="right" bgcolor="#3399ff">
      <font color="#FFFFFF">联系电话:</font>
     </td>
     <td height="28">
      <input type="text" name="cateMember.cateMemberTel"
       value="${cateMember.cateMemberTel}">
     </td>
    </tr>
    <tr>
     <td height="26" align="right" bgcolor="#3399ff">
      <font color="#FFFFFF">邮箱:</font>
     </td>
     <td height="26">
      <input type="text" name="cateMember.cateMemberEmail"
       value="${cateMember.cateMemberEmail}">
     </td>
    </tr>
    <tr>
     <td height="30" align="right" bgcolor="#3399ff">
      <font color="#FFFFFF">审核:</font>
     </td>
     <td height="30">
      <input type="checkbox" name="cateMember.cateMemberAudit" ${cateMember.cateMemberAudit}>
      <font>通过审核</font>
     </td>
    </tr>
    <tr>
     <td height="30" align="right" bgcolor="#3399ff">
      <font color="#FFFFFF">用户权限标识:</font>
     </td>
     <td height="30">
      <select name="cateMember.cateMemberMark">
       <option value="-2" <%if(request.getAttribute("cateMember.cateMemberMark").equals("-2")){out.print("selected");} %>>
        普通会员
       </option>
       <option value="-1" <%if(request.getAttribute("cateMember.cateMemberMark").equals("-1")){out.print("selected");} %>>
        高级会员
       </option>
       <option value="0" <%if(request.getAttribute("cateMember.cateMemberMark").equals("0")){out.print("selected");} %>>
        管理员
       </option>
      </select>
     </td>
    </tr>
    <tr>
     <td height="34" colspan="2" align="center">
      <input type="submit" name="Submit" value="更新">
     </td>
    </tr>
   </table>
  </s:form>


 

  评论这张
 
阅读(488)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018