2012年6月29日

          最近寫了個項目,自己第一次搭建架構,費了好久才搭成功,記錄下來,為以后留個參考。
          前臺使用的是jquery
          web.xml 
           2   <context-param>
           3     <param-name>contextConfigLocation</param-name>
           4         <param-value>
           5           classpath*:applicationContext-common.xml, 
           6           classpath*:applicationContext-dao.xml,
           7           classpath*:applicationContext-service.xml,
           8           classpath*:applicationContext-action.xml
           9         </param-value>
          10   </context-param>
          11   
          12   <welcome-file-list>
          13     <welcome-file>login.jsp</welcome-file>
          14   </welcome-file-list>
          15   <filter>
          16         <filter-name>struts2</filter-name>
          17         <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
          18   </filter>
          19   
          20     <filter-mapping>
          21         <filter-name>struts2</filter-name>
          22         <url-pattern>/*</url-pattern>
          23     </filter-mapping>
          24         <listener>
          25         <listener-class>
          26             org.springframework.web.context.ContextLoaderListener 
          27         </listener-class>
          28     </listener>
          29     <session-config> 
          30         <session-timeout>20</session-timeout> 
          31     </session-config>
          32     <filter>
          33        <filter-name>struts-cleanup</filter-name>
          34        <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
          35     </filter>
          36     <filter-mapping>
          37        <filter-name>struts-cleanup</filter-name>
          38        <url-pattern>/*</url-pattern>
          39     </filter-mapping>

          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"
          >

          <struts>
              <package name="default" namespace="/com" extends="struts-default">
                 
                  <action name="login" class="loginAction" method="login">
                      <result name="success">/main.jsp</result>
                      <result name="error">/loginError.jsp</result>
                      <result name="fail">/error.jsp</result>
                  </action>
                  <action name="logoff" class="logoffAction" method="logoff">
                      <result name="success" type="redirect">/login.jsp</result> 
                  </action>
              </package>
          </struts>

          applicationContext-xxx.xml下面這四個其實可以放在一個配置檔里,區(qū)分下來只是為了便于查找清晰點

          applicationContext-action.xml
          1 <bean id="loginAction" class="com.ivo.action.LoginAction" scope="prototype">
          2         <property name="checkAuthorityService" ref="checkAuthorityService" />
          3     </bean>

          applicationContext-service.xml
          1  <bean id="checkAuthorityService" class="com.ivo.service.impl.CheckAuthorityService">
          2         <property name="uasUserDao" ref="uasUserDao" />
          3     </bean>    

          applicationContext-dao.xml
          1 <bean id="uasUserDao" class="com.ivo.dao.impl.UasUserDao">
          2         <property name="sqlMapClient" ref="sqlMapClient" />
          3     </bean>

          applicationCtontext-common.xml
           1 <bean id="mySqlDataSource"
           2         class="org.springframework.jdbc.datasource.DriverManagerDataSource">
           3         <property name="driverClassName">
           4             <value>com.mysql.jdbc.Driver</value>
           5         </property>
           6         <property name="url">
           7             <value>
           8                 jdbc:mysql://10.20.53.106:3306/qrademo
           9             </value>
          10         </property>
          11         <property name="username">
          12             <value>root</value>
          13         </property>
          14         <property name="password">
          15             <value>Ivo123</value>
          16         </property>
          17     </bean>
          18 <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
          19         <property name="configLocation">
          20             <value>classpath:ibatis-config.xml</value>
          21         </property>
          22         <property name="dataSource">
          23             <ref local="mySqlDataSource" />
          24         </property>
          25     </bean>

          ibatis-config.xml
          1 <sqlMapConfig>
          2     <settings cacheModelsEnabled="true" enhancementEnabled="true" lazyLoadingEnabled="true"
          3         maxRequests="300" maxSessions="200" maxTransactions="100" useStatementNamespaces="true" />
          4
             <sqlMap resource="com/ivo/pojo/xml/UasUser.xml" />
          5 </sqlMapConfig>

          差不多建這些,當然還有許多jar包需要導



          posted @ 2012-06-29 19:28 幻破 閱讀(117) | 評論 (0)編輯 收藏
           
          最近寫了個功能jqgrid的某個欄位下載文件,本來直接用<a href=""/>直接鏈接的,但是出現(xiàn)了文件名含中文的就報錯的現(xiàn)象,且若文件類型為.txt則直接打開。然后我糾結啊!
          然后百度到網(wǎng)上有人使用struts2下載文件解決了這個問題,然后就借用了看看。
          jquery代碼
           1 function rangFun(value, options, rData){
           2           return '<a href=entCom/download.action?filename='+rData['range_id']+'>'+rData['range_id']+'</a>';
           3      }
           4  $("#externalListGrd").jqGrid({
           5          datatype    : "json",
           6          mtype       : "POST",
           7          width       : 720 ,
           8          height      : 420,
           9          rownumWidth : true,
          10          shrinkToFit : false,
          11          scroll      : true,
          12         ondblClickRow:regectExtFun,
          13          colNames    : ['允許范圍'],
          14          colModel:[
          15             { name : 'range_id',   index : 'range_id',   width : 50, align: "left",sortable : "true",formatter:rangFun}]
          16    })

          struts.xml里的配置
          1 <action name="download" class="com.ivo.action.DownloadAction">
          2            <result name="success" type="stream">
          3               <param name="contentType">text/html,application/vnd.ms-powerpoint,application/vnd.ms-word,application/vnd.ms-excel,text/plain</param> //文件打開方式
          4               <param name="inputName">inputStream</param>
          5               <param name="contentDisposition">attachment;filename="${filename}"</param>
          6               <param name="bufferSize">2048</param>
          7            </result>
          8         </action>

          后臺代碼
           1 package com.ivo.action;
           2 
           3 import java.io.FileInputStream;
           4 import java.io.InputStream;
           5 import java.io.UnsupportedEncodingException;
           6 
           7 import com.opensymphony.xwork2.ActionSupport;
           8 
           9 public class DownloadAction extends ActionSupport {
          10    private String filename;
          11    public InputStream getInputStream() throws Exception{
          12        String downloadFileName=filename;
          13         try {
          14             // downloadFileName = new String(downloadFileName.getBytes(),"UTF-8");這樣帶中文名的文件依舊會報錯,想了半天找前輩幫忙看,后來改成下面的才OK。原因是從前臺傳過來的時候字符已經(jīng)亂碼,所以需要重新解析,再轉(zhuǎn)換
          15             downloadFileName = new String(downloadFileName.getBytes("ISO-8859-1"),"UTF-8");
          16 
          17         } catch(UnsupportedEncodingException e) {
          18 
          19             e.printStackTrace();
          20 
          21         }
          22        String dir = "D:\\qra\\fileUpload\\"+downloadFileName;
          23        return new FileInputStream(dir);
          24    }
          25 
          26     public String getFilename() {
          27         return filename;
          28     }
          29 
          30     public void setFilename(String filename) {
          31         this.filename = filename;
          32     }
          33    
          34 }



          posted @ 2012-06-29 19:08 幻破 閱讀(182) | 評論 (0)編輯 收藏

          2012年2月13日

          最近遇到這種問題,相當煩惱。還好網(wǎng)上有個解決方法不錯,copy過來自己保留著。
          不過我是在rem Guess CATALINA_HOME if not defined后面添加的set JAVA_OPTS=-Xms64m -Xmx256m -XX:PermSize=128M -XX:MaxNewSize=256m -XX:MaxPermSize=256m
          鏈接地址:
          http://blog.sina.com.cn/s/blog_3caf06b20100czvo.html 
          posted @ 2012-02-13 09:23 幻破 閱讀(139) | 評論 (0)編輯 收藏

          2012年2月8日

          $(function() {
          var dates = $( "#from, #to" ).datepicker({
          defaultDate: "+1w",/*當前時間加一周*/
          dateFormat: 'yy-mm-dd',//日期格式
          changeMonth: true,
          changeYear:true, //可選擇年份
          numberOfMonths: 1,//設置一次顯示幾個月
          onSelect: function( selectedDate ) {
          var option = this.id == "from" ? "minDate" : "maxDate",
          instance = $( this ).data( "datepicker" ),
          date = $.datepicker.parseDate(
          instance.settings.dateFormat ||
          $.datepicker._defaults.dateFormat,
          selectedDate, instance.settings );     //還沒搞懂?
          dates.not( this ).datepicker( "option", option, date );
          }
          });
          });

          posted @ 2012-02-08 18:51 幻破 閱讀(203) | 評論 (0)編輯 收藏
          僅列出標題  
           
          主站蜘蛛池模板: 栖霞市| 鹤庆县| 思南县| 澄江县| 玉林市| 呼伦贝尔市| 米脂县| 昆山市| 漯河市| 中超| 新绛县| 资溪县| 凤台县| 嘉兴市| 类乌齐县| 民乐县| 正宁县| 天峻县| 乐山市| 曲松县| 安西县| 新邵县| 鸡东县| 海林市| 米脂县| 大冶市| 南和县| 板桥市| 黄龙县| 南安市| 镇宁| 金溪县| 普安县| 青州市| 梁平县| 萨嘎县| 荃湾区| 太原市| 上饶县| 烟台市| 罗田县|