2012年6月29日

          最近寫了個(gè)項(xiàng)目,自己第一次搭建架構(gòu),費(fèi)了好久才搭成功,記錄下來,為以后留個(gè)參考。
          前臺(tái)使用的是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下面這四個(gè)其實(shí)可以放在一個(gè)配置檔里,區(qū)分下來只是為了便于查找清晰點(diǎn)

          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>

          差不多建這些,當(dāng)然還有許多jar包需要導(dǎo)



          posted @ 2012-06-29 19:28 幻破 閱讀(117) | 評(píng)論 (0)編輯 收藏
           
          最近寫了個(gè)功能jqgrid的某個(gè)欄位下載文件,本來直接用<a href=""/>直接鏈接的,但是出現(xiàn)了文件名含中文的就報(bào)錯(cuò)的現(xiàn)象,且若文件類型為.txt則直接打開。然后我糾結(jié)啊!
          然后百度到網(wǎng)上有人使用struts2下載文件解決了這個(gè)問題,然后就借用了看看。
          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>

          后臺(tái)代碼
           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");這樣帶中文名的文件依舊會(huì)報(bào)錯(cuò),想了半天找前輩幫忙看,后來改成下面的才OK。原因是從前臺(tái)傳過來的時(shí)候字符已經(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 幻破 閱讀(183) | 評(píng)論 (0)編輯 收藏

          2012年2月13日

          最近遇到這種問題,相當(dāng)煩惱。還好網(wǎng)上有個(gè)解決方法不錯(cuò),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) | 評(píng)論 (0)編輯 收藏

          2012年2月8日

          $(function() {
          var dates = $( "#from, #to" ).datepicker({
          defaultDate: "+1w",/*當(dāng)前時(shí)間加一周*/
          dateFormat: 'yy-mm-dd',//日期格式
          changeMonth: true,
          changeYear:true, //可選擇年份
          numberOfMonths: 1,//設(shè)置一次顯示幾個(gè)月
          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 幻破 閱讀(204) | 評(píng)論 (0)編輯 收藏
          僅列出標(biāo)題  
           
          主站蜘蛛池模板: 宿松县| 西青区| 祁东县| 南汇区| 景德镇市| 安吉县| 大渡口区| 平定县| 涟水县| 甘谷县| 和顺县| 阿尔山市| 霞浦县| 和龙市| 安龙县| 大冶市| 建瓯市| 历史| 丰原市| 九龙坡区| 保康县| 沧州市| 灌阳县| 延寿县| 都江堰市| 江都市| 武威市| 江山市| 黄陵县| 通榆县| 沙洋县| 疏勒县| 土默特左旗| 延长县| 红桥区| 灌云县| 泸溪县| 屯昌县| 永仁县| 乡城县| 高尔夫|