Struts Spring Hibern

发布时间:2019-09-14 09:26:43编辑:auto阅读(1698)

    三、QueryToDayInfoAction

    <!--[if !supportEmptyParas]--> <!--[endif]-->

    package com.jh.xh.action;

    <!--[if !supportEmptyParas]--> <!--[endif]-->

    import javax.servlet.http.HttpServletRequest;

    import javax.servlet.http.HttpServletResponse;

    <!--[if !supportEmptyParas]--> <!--[endif]-->

    import org.apache.struts.action.Action;

    import org.apache.struts.action.ActionForm;

    import org.apache.struts.action.ActionForward;

    import org.apache.struts.action.ActionMapping;

    import org.hibernate.criterion.DetachedCriteria;

    import org.hibernate.criterion.Order;

    import org.springframework.web.context.WebApplicationContext;

    import org.springframework.web.context.support.WebApplicationContextUtils;

    <!--[if !supportEmptyParas]--> <!--[endif]-->

    import com.jh.xh.common.PaginationSupport;

    import com.jh.xh.hibernate.pojo.InfoTab;

    import com.jh.xh.spring.service.UserManager;

    <!--[if !supportEmptyParas]--> <!--[endif]-->

    /**

     * Creation date: 03-22-2007

     */

    public class QueryToDayInfoAction extends Action {

       

        private UserManager userManager;

    <!--[if !supportEmptyParas]--> <!--[endif]-->

        public UserManager getUserManager() {

            return userManager;

        }

    <!--[if !supportEmptyParas]--> <!--[endif]-->

        public void setUserManager(UserManager userManager) {

            this.userManager = userManager;

        }

    <!--[if !supportEmptyParas]--> <!--[endif]-->

        public ActionForward execute(ActionMapping mapping, ActionForm form,

               HttpServletRequest request, HttpServletResponse response) {

    <!--[if !supportEmptyParas]--> <!--[endif]-->

            WebApplicationContext wac = WebApplicationContextUtils

                   .getRequiredWebApplicationContext(this.getServlet()

                          .getServletContext());

    <!--[if !supportEmptyParas]--> <!--[endif]-->

            this.userManager = (UserManager) wac.getBean("userManager");

    <!--[if !supportEmptyParas]--> <!--[endif]-->

            DetachedCriteria detachedCriteria = DetachedCriteria

                   .forClass(InfoTab.class);

          

            detachedCriteria.addOrder(Order.desc("id"));

    <!--[if !supportEmptyParas]--> <!--[endif]-->

            String _startIndex; // 当前页;

            _startIndex = (String) request.getParameter("startIndex");

    <!--[if !supportEmptyParas]--> <!--[endif]-->

           int startIndex;

    <!--[if !supportEmptyParas]--> <!--[endif]-->

           if (_startIndex == null) {

               startIndex = 0;

           } else {

               startIndex = Integer.parseInt(_startIndex);

           }

    <!--[if !supportEmptyParas]--> <!--[endif]-->

            PaginationSupport ps = userManager.findPageByCriteria(detachedCriteria,

                   PaginationSupport.PAGESIZE, startIndex);

            request.setAttribute("ps", ps);

    <!--[if !supportEmptyParas]--> <!--[endif]-->

            return mapping.findForward("todayinfolist");

        }

    <!--[if !supportEmptyParas]--> <!--[endif]-->

    }

    <!--[if !supportEmptyParas]--> <!--[endif]-->

    <!--[if !supportEmptyParas]--> <!--[endif]-->

    action-servlet.xml 配置文件
    <!--[if !supportEmptyParas]--> <!--[endif]-->

    <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"

        "http://www.springframework.org/dtd/spring-beans.dtd">

    <!--[if !supportEmptyParas]--> <!--[endif]-->

    <beans>

    <!--[if !supportEmptyParas]--> <!--[endif]-->

        <!-- Define Struts Actions here -->

    <!--[if !supportEmptyParas]--> <!--[endif]-->

        <bean name="/queryToDayInfo"

            class="com.jh.xh.action.QueryToDayInfoAction" singleton="false">

            <property name="userManager">

               <ref bean="userManager" />

            </property>

        </bean>

    <!--[if !supportEmptyParas]--> <!--[endif]-->

    </beans>

    <!--[if !supportEmptyParas]--> <!--[endif]-->

    <!--[if !supportEmptyParas]--> <!--[endif]-->

    struts-config.xml 配置文件
    <!--[if !supportEmptyParas]--> <!--[endif]-->

            <action path="/queryToDayInfo" scope="request"

               type="org.springframework.web.struts.DelegatingActionProxy"

               validate="false">

               <forward name="todayinfolist" path="/todayinfolist.jsp" />

            </action>

    <!--[if !supportEmptyParas]--> <!--[endif]-->

        <plug-in

            className="org.springframework.web.struts.ContextLoaderPlugIn">

            <set-property property="contextConfigLocation"

               value="/WEB-INF/applicationContext.xml,/WEB-INF/action-servlet.xml" />

        </plug-in>

    <!--[if !supportEmptyParas]--> <!--[endif]-->

    <!--[if !supportEmptyParas]--> <!--[endif]-->

    <!--[if !supportEmptyParas]--> <!--[endif]-->

    web.xml 文件配置
    <!--[if !supportEmptyParas]--> <!--[endif]-->

        <context-param>

            <param-name>contextConfigLocation</param-name>

            <param-value>/WEB-INF/applicationContext.xml</param-value>

        </context-param>

    <!--[if !supportEmptyParas]--> <!--[endif]-->

        <listener>

            <listener-class>

               org.springframework.web.context.ContextLoaderListener

            </listener-class>

        </listener>

    <!--[if !supportEmptyParas]--> <!--[endif]-->

关键字