Chinaunix首页 | 论坛 | 博客
  • 博客访问: 476350
  • 博文数量: 111
  • 博客积分: 3146
  • 博客等级: 中校
  • 技术积分: 939
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-07 11:23
个人简介

Nathing

文章分类

全部博文(111)

文章存档

2016年(2)

2015年(1)

2014年(31)

2012年(2)

2011年(9)

2010年(36)

2009年(30)

我的朋友

分类: Java

2010-11-01 10:40:54

1.导入spring和struts1的jar包.

2.配置web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="" xmlns="" xmlns:web="/web-app_2_5.xsd" xsi:schemaLocation=" /web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>serializationObject</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>2</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>2</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
  </servlet>


  <!-- Standard Action Servlet Mapping -->
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
 
  <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:beans.xml</param-value>
  </context-param>
  <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  
</web-app>


3.配置struts-config.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
          "">

<struts-config>
    <form-beans>
        <form-bean name="championsForm" type="com.jj.serializ.web.actionForm.ChampionsForm" />
    </form-beans>

    <action-mappings>
        <action path="/champions"
                type="com.jj.serializ.web.action.ChampionsAction"
                name="championsForm"
                scope="request"
                parameter="method">
            <forward name="list" path="/list.jsp"></forward>
        </action>

    </action-mappings>
    
    <controller processorClass="org.springframework.web.struts.AutowiringRequestProcessor" />

</struts-config>


4.配置beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
     xmlns:xsi=""
     xmlns:aop=""
     xmlns:tx=""
     xsi:schemaLocation=" /spring-beans-2.0.xsd
            /spring-aop-2.0.xsd
            /spring-tx-2.0.xsd"
>

    <bean id="reportDAO" class="com.jj.serializ.dao.impl.ReportDAOImpl"/>
    
    <bean id="reportManager" class="com.jj.serializ.manager.impl.ReportManagerImpl">
        <property name="reportDAO" ref="reportDAO"></property>
    </bean>
    
    <bean id="champions" class="com.jj.serializ.web.action.ChampionsAction">
        <property name="reportManager" ref="reportManager"></property>
    </bean>
    
</beans>


Action:

public class ChampionsAction extends DispatchAction
{
    private ReportManager reportManager;
    
    public ActionForward list(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception
    {
        
        reportManager.save();
        List<Report> list = reportManager.load();
        System.out.println(list.size());
        request.setAttribute("list", list);
        
        return mapping.findForward("list");
    }

    public void setReportManager(ReportManager reportManager)
    {
        this.reportManager = reportManager;
    }
    
}


Jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<table border="1" align="center" cellpadding="1" cellspacing="0">
<tr bgcolor="#EFF3F7">
    <td><b>abs_index</b></td>
    <td><b>day_index</b></td>
    <td><b>name</b></td>
    <td><b>province</b></td>
    <td><b>sex</b></td>
    <td><b>reportVersion</b></td>
</tr>
    <c:forEach items="${list}" var="report">
    <tr>
        <td>${report.abs_index}</td>
        <td>${report.day_index}</td>
        <td>${report.name}</td>
        <td>${report.province}</td>
        <c:if test="${report.sex eq 0}">
            <td></td>
        </c:if>
        <c:if test="${report.sex eq 1}">
            <td></td>
        </c:if>
        <td>${report.reportVersion}</td>
    </tr>    
    </c:forEach>
</table>    
</body>
</html>


阅读(722) | 评论(1) | 转发(0) |
0

上一篇:Java序列化算法透析

下一篇:Ibtis_spring

给主人留下些什么吧!~~

chinaunix网友2010-11-01 17:51:29

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com