---
title: "广告项目:（1 ）文件上传"
author: "chennaid2"
date: "2012-05-03T13:49:39Z"
tags: []
categories: ["非技术"]
slug: "1"
draft: false
lastmod: "2012-05-02T16:06:58Z"
id: 1507708
url: "https://chennaid2.iteye.com/blog/1507708"
---

**文件上传：**

 

Struts文件上传心得：

 

1.使用 org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper;这个拦截器，在action被调用之前，会**首先**走到fileUpload拦截器（对应的是FileUploadInterceptor类），在这个拦截器中，会先看一下request是不是 MultiPartRequestWrapper,如果不是，就说明不是上传文件用的request，fildUpload拦截器会直接将控制权交给下一个拦截器；如果是，就会把request对象强转为MultiPartRequestWrapper对象，然后调用hasErrors方法，看看有没有上传时候产生的错误，有的话，就直接加到了Action的错误（Action级别的）中了。另外，在fileUpload拦截器中会将MultiPartRequestWrapper对象中放置的文件全取出来，把文件、文件名、文件类型取出来，放到request的parameters中，这样到了params拦截器时，就可以轻松的将这些内容注入到Action中了，这也就是为什么fileUpload拦截器需要放在params拦截器前面的理由。在文件都放到request的parameters对象里之后，fileUpload拦截器会继续调用其他拦截器直到Action等执行完毕，他还要做一个扫尾的工作：把临时文件夹中的文件删除（这些文件是由commons-fileupload组件上传的，供你在自己的Action中将文件copy到指定的目录下，当action执行完了后，这些临时文件当然就没用了）。

 

2.Struts 2的文件上传，底层还是由apache的commons-fileupload 实现的。

 

3.配置文件：

&lt;!-- 上传的文件存放目录 --&gt;

 &lt;constant name="struts.multipart.saveDir" value="tmp"/&gt;  
   
   
 &lt;!-- 参数struts.multipart.maxSize 为文件尺寸   默认是2M，如果不进行配置上传超出2M，会抛出错误 --&gt;  
 &lt;constant name="struts.multipart.maxSize" value="2000000" /&gt;

 

 

 

 

4.页面的标签：标签的名字一是“upload”

 

&lt;input title="浏览..." value=""  id="file\_id" name="upload" class="e\_inputfile" onfocus="this.className='e\_inputFocusfile'" onblur="this.className='e\_inputfile'" type="file" /&gt; 

 

5.1  页面代码：

 

upload.jsp

 

&lt;%@ page language="java" import="java.util.\*" pageEncoding="utf-8"%&gt;  
&lt;%  
 String path = request.getContextPath();  
 String basePath = request.getScheme() + "://"  
   + request.getServerName() + ":" + request.getServerPort()  
   + path + "/";  
%&gt;  
&lt;%@ taglib prefix="c" uri="/WEB-INF/tags/c.tld" %&gt;  
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd](http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd)"&gt;  
&lt;html xmlns="[http://www.w3.org/1999/xhtml](http://www.w3.org/1999/xhtml)"&gt;  
&lt;head&gt;  
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;  
&lt;title&gt;广告系统&lt;/title&gt;  
&lt;link href="&lt;%=path %&gt;/css/platform.css" rel="stylesheet" type="text/css"  /&gt;

&lt;!-- JQUERY 主要JS库 --&gt;  
&lt;script type="text/javascript" src="&lt;%=path %&gt;/js/lib/jquery.js"&gt;&lt;/script&gt;  
&lt;!-- JSTREE 主要JS库--&gt;  
&lt;script type="text/javascript" src="&lt;%=path %&gt;/js/lib/jquery.cookie.js"&gt;&lt;/script&gt;  
&lt;script type="text/javascript" src="&lt;%=path %&gt;/js/lib/jquery.hotkeys.js"&gt;&lt;/script&gt;  
&lt;script type="text/javascript" src="&lt;%=path %&gt;/js/jquery.jstree.js"&gt;&lt;/script&gt;  
&lt;script type="text/javascript" src="&lt;%=path %&gt;/js/util.js"&gt;&lt;/script&gt;  
&lt;script type="text/javascript" src="&lt;%=path %&gt;/jquery/jquery.form.js"&gt;&lt;/script&gt;

&lt;script type="text/javascript"&gt;     
 function changeBody(index){      
  switch(index){      
   case 1:{      
    document.getElementById('wm-info').style.display = "";         
   break;      
   }      
  }     
 }     
 function close(){  
  ocument.getElementById("wm-info").style.display ="none";         
 }   
&lt;/script&gt;  
&lt;script type="text/javascript"&gt;

 var sel\_node\_id;  
   
 //公共方法--获得dom对象  
 function getObj(id){  
  var obj = document.getElementById(id);  
  return obj;   
 }  
   
 //公共方法-选择下拉框的值  
 function selectOptionVal(id){  
  var positionVal="-1";  
  var selectPobj = getObj(id);  
  var options   = selectPobj.options;  
  for(var i = 0; i &lt; options.length; i++){  
   var optionResult = options\[i].selected ;  
   if(optionResult){  
    positionVal = options\[i].value;  
   }  
  }  
  return positionVal;  
 }

 //检查input框，路径不能为空  
 function checkFileName(){  
    
  var uploadFilePath = getObj("file\_id").value;  
  //alert("上传文件的路径"+uploadFilePath);  
  if(uploadFilePath == "" || uploadFilePath == null || uploadFilePath == undefined){  
   alert("上传的文件不能为空!");  
   return false;  
  }  
  return true;  
 }  
   
 //检查通过开始提交,后开始验证到上传文件  
 function submitForm(nodeId,materialTypeVal,postionTypeVal,positionVal,iscover){  
  var form = $("form\[name=form1]"); //其中的form1是我form的名称     
    var options  = {     
   [**url:'&lt;%=application.getContextPath**](/admin/blogs/1507708/'%3C%=application.getContextPath)**() %&gt;/material/checkMaterial.do',**  
   type:'post',  
   dataType:'json',    
   data: {nodeTypeId:nodeId,materialType:materialTypeVal,postionType:postionTypeVal, positionId:positionVal,cover:iscover},     
   success:function(data){  
    var flag = data.result;   
    if(flag){  
     alert("上传成功");  
    }else{  
     alert("上传失败,原因:"+data.msg);  
    }  
            
    }    
   };    
        form.ajaxSubmit(options);  

 }  
   
 //提交前先审核  
 function checkFile(){

  var nodeId = getObj("treeNodeId").value;

  if(nodeId == null || nodeId == undefined){  
   alert("请选择素材分类树的节点！");  
   return;  
  }  
    
  //确定那个素材分类  
  var materialType = selectOptionVal("sel\_material\_type");  
  if(materialType == "-1"){  
   alert("请选择-素材分类！");  
   return;  
  }  
    
  //确定那个素材类型  
  var postionType = selectOptionVal("sel\_postion\_type");  
  if(postionType == "-1"){  
   alert("请选择-素材类型！");  
   return;  
  }  
    
  //确定那个广告位的素材  
  var positionVal = selectOptionVal("sel\_postion\_id");  
  if(positionVal == "-1"){  
   alert("请选择-广告位！");  
   return;  
  }  
    
  if(!checkFileName()){  
   return;  
  }

  var form = $("form\[name=form1]"); //其中的form1是我form的名称    
        var options  = {    
    [url:'&lt;%=application.getContextPath](/admin/blogs/1507708/'%3C%=application.getContextPath)() %&gt;/material/checkFileName.do',  
   type:'post',  
   dataType:'json',    
   data: {nodeTypeId:nodeId},     
   success:function(data){  
    var flag = data.result;   
    var isHasSame = data.isHasSame;   
    if(flag){  
     if(isHasSame){  
      if(confirm("有同名的文件,确定要覆盖吗?")){  
       submitForm(nodeId,materialType,postionType,positionVal,1);  
      }else{  
       alert("请您修改上传文件的名字！");  
      }  
     }else{  
      submitForm(nodeId,materialType,postionType,positionVal,0);  
     }  
    }else{  
     alert("上传失败,原因:"+data.msg);  
    }  
    },  
    async:false    
   };    
        form.ajaxSubmit(options);  

    
 }  
   
&lt;/script&gt;

&lt;script type="text/javascript"&gt;

 //加载树  
 function init(){  
  $.ajax({  
   type:"post",  
   //url: getContextPath() + '/material/listMaterialType.do',  
   url: "&lt;%=application.getContextPath() %&gt;/material/listMaterialType.do",  
   dataType :"String",  
   success:function(json){  
    var str = json.replace(/\\"id"/g, 'attr:{"id"');  
    var str2 = str.replace(/\\,"data"/g, '},data');  
    var jsondata = eval(str2);  
       jtree(jsondata);  
   },  
   error:function(){  
    alert("服务器异常,请稍后重试!");  
   },  
   async:false  
  });  
  }     
      
  function jtree(o){  
   var ctxPath = "&lt;%=path%&gt;";  
   $("#tree").jstree(  
    //json加载数据节点       
    {    
     
     //json数据区域   
        "json\_data" :{data:o}  
      ,  
     //要使用到的插件  
            "plugins" : \[ "themes", "json\_data", "ui", "crrm", "cookies", "types"]  
                ,  
             "types" : {  
              "max\_depth" : -2,  
              "max\_children" : -2,  
              "valid\_children" : \[ "drive" ],  
              "types" : {  
               "default" : {  
                "valid\_children" :"none",  
                "icon" : {  
                 "image" : ctxPath+"/images/folder.png"  
                }  
               }  
              }  
             }  
          })  
         
      //选择事件  
   .bind("select\_node.jstree", function(e, data) {  
          var id = parseInt(data.rslt.obj.attr("id"));  
          document.getElementById("treeNodeId").value =id;  
         })  
                   
  }  
&lt;/script&gt;  
&lt;/head&gt;  
&lt;body onload="init()"&gt;

&lt;!--  
 &lt;form action=""  id="form1" name="form1"  enctype="multipart/form-data" &gt;  
 --&gt;  
&lt;form action=""  id="form1" name="form1"  &gt;

&lt;input type="hidden" value="" id="treeNodeId" /&gt;

 &lt;table cellpadding="0" cellspacing="1" class="servicesT"&gt;  
  &lt;tr&gt;  
   &lt;th class="formTitle" colspan="99"&gt;  
    &lt;span&gt;上传素材&lt;/span&gt;    
   &lt;/th&gt;  
  &lt;/tr&gt;  
  &lt;tr&gt;  
   &lt;td class="td\_label"&gt;选择素材分类：&lt;/td&gt;  
   &lt;td class="td\_input"&gt;  
    &lt;select id="sel\_material\_type"   onchange="selectOptionVal(this.id)"  class="e\_select" onfocus="this.className='e\_selectFocus'" onblur="this.className='e\_select'" &gt;  
     &lt;option id="ad\_id" value="-1"&gt;请选择...&lt;/option&gt;  
     &lt;c:forEach items="${mKindList}" var="materialBean"&gt;  
      &lt;option  value="${materialBean.id }"&gt;${materialBean.name }&lt;/option&gt;  
     &lt;/c:forEach&gt;  
      
    &lt;!--  
    &lt;option value="0" &gt;文字&lt;/option&gt;  
    &lt;option value="1" &gt;图片&lt;/option&gt;  
    &lt;option value="2" &gt;视频&lt;/option&gt;  
    &lt;option value="3" &gt;压缩包&lt;/option&gt;  
     --&gt;  
    &lt;/select&gt;    
   &lt;/td&gt;  
   &lt;td class="td\_label"&gt;选择素材类型：&lt;/td&gt;  
   &lt;td class="td\_input"&gt;  
    &lt;select id="sel\_postion\_type"  onchange="selectOptionVal(this.id)"  class="e\_select"  onfocus="this.className='e\_selectFocus'"  onblur="this.className='e\_select'" &gt;  
     &lt;option id="ad\_id" value="-1"&gt;请选择...&lt;/option&gt;  
     &lt;c:forEach items="${mTypeList}" var="materialBean"&gt;  
      &lt;option  value="${materialBean.id }"&gt;${materialBean.name }&lt;/option&gt;  
     &lt;/c:forEach&gt;  
    &lt;!--  
     &lt;option value="1" &gt;标清&lt;/option&gt;  
     &lt;option value="2" &gt;高清&lt;/option&gt;  
    --&gt;  
    &lt;/select&gt;    
   &lt;/td&gt;  
   &lt;!-- &lt;td class="td\_label"&gt;选择广告位：&lt;/td&gt;  
   &lt;td class="td\_input"&gt;  
    &lt;select  id="sel\_postion\_id" onchange="selectOptionVal(this.id)"   class="e\_select"  onfocus="this.className='e\_selectFocus'" onblur="this.className='e\_select'" &gt;  
     &lt;option id="ad\_id" value="-1"&gt;请选择...&lt;/option&gt;  
     &lt;c:forEach items="${pNameList}" var="positionBean"&gt;  
      &lt;option  value="${positionBean.id }"&gt;${positionBean.positionNameCn }&lt;/option&gt;  
     &lt;/c:forEach&gt;  
      
     &lt;option id="ad\_id" value="1"&gt;换台广告&lt;/option&gt;  
     &lt;option id="ad\_id" value="2"&gt;音量广告&lt;/option&gt;  
     &lt;option id="ad\_id" value="3"&gt;频道列表广告&lt;/option&gt;  
     &lt;option id="ad\_id" value="4"&gt;循环播放广告&lt;/option&gt;  
     &lt;option id="ad\_id" value="5"&gt;菜单广告&lt;/option&gt;  
      
    &lt;/select&gt;    
   &lt;/td&gt;  --&gt;  
  &lt;/tr&gt;  
  &lt;tr&gt;  
     
   &lt;td class="td\_label"&gt;选择广告位：&lt;/td&gt;  
   &lt;td class="td\_input"&gt;&lt;select  id="sel\_postion\_id" onchange="selectOptionVal(this.id)"   class="e\_select"  onfocus="this.className='e\_selectFocus'" onblur="this.className='e\_select'" &gt;  
     &lt;option id="ad\_id" value="-1"&gt;请选择...&lt;/option&gt;  
     &lt;c:forEach items="${pNameList}" var="positionBean"&gt;  
      &lt;option  value="${positionBean.id }"&gt;${positionBean.positionNameCn }&lt;/option&gt;  
     &lt;/c:forEach&gt;  
    &lt;!--  
     &lt;option id="ad\_id" value="1"&gt;换台广告&lt;/option&gt;  
     &lt;option id="ad\_id" value="2"&gt;音量广告&lt;/option&gt;  
     &lt;option id="ad\_id" value="3"&gt;频道列表广告&lt;/option&gt;  
     &lt;option id="ad\_id" value="4"&gt;循环播放广告&lt;/option&gt;  
     &lt;option id="ad\_id" value="5"&gt;菜单广告&lt;/option&gt;  
     --&gt;  
    &lt;/select&gt; &lt;/td&gt;  
    &lt;td class="td\_label"&gt;选择文件：&lt;/td&gt;  
   &lt;td class="td\_input"&gt;  
    &lt;input title="浏览..." value=""  id="file\_id" name="upload" class="e\_inputfile" onfocus="this.className='e\_inputFocusfile'" onblur="this.className='e\_inputfile'" type="file" /&gt;  &lt;/td&gt;  
     &lt;/tr&gt;  
  &lt;tr&gt;  
   &lt;td class="td\_labela"&gt;选择类型：&lt;br /&gt;&lt;br /&gt;（大类别包括多个小类别）&lt;/td&gt;  
   &lt;td colspan="5" class="td\_inputaa" valign="top"&gt;  
   &lt;div id="tree" class="tree"  &gt;&lt;/div&gt;  
    
     
   &lt;/td&gt;  
     &lt;/tr&gt;  
    
  &lt;tr&gt;  
   &lt;td class="formBottom" colspan="99"&gt;  
    &lt;input name="Submit"  
    type="button"  
    title="上传"  
    class="b\_next"  
    value=""  
    **onclick="checkFile()"**  
    /&gt;  
       
             &lt;/td&gt;     
                 
  &lt;/tr&gt;  
 &lt;/table&gt;  
&lt;/form&gt;  
&lt;/body&gt;  
&lt;/html&gt;

5.2 struts.xml配置文件代码

 

&lt;?xml version="1.0" encoding="UTF-8" ?&gt;  
&lt;!DOCTYPE struts PUBLIC  
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  
    "[http://struts.apache.org/dtds/struts-2.0.dtd](http://struts.apache.org/dtds/struts-2.0.dtd)"&gt;  
&lt;struts&gt;  
 &lt;!-- global --&gt;  
 &lt;include file="struts-default.xml" /&gt;  
 &lt;include file="struts-plugin.xml" /&gt;

 &lt;include file="struts/struts-playItem.xml" /&gt;  
 &lt;include file="struts/struts-twowayAdvert.xml" /&gt;

 &lt;constant name="struts.enable.DynamicMethodInvocation" value="false" /&gt;

 &lt;!-- 指定Web应用的默认编码集,相当于调用HttpServletRequest的setCharacterEncoding方法 --&gt;  
 &lt;constant name="struts.i18n.encoding" value="UTF-8" /&gt;  
   
 &lt;!-- 配置国际化相关信息 --&gt;  
 &lt;constant name="struts.custom.i18n.resources" value="struts.messageResource" /&gt;

 &lt;!-- 设置浏览器是否缓存静态内容,默认值为true(生产环境下使用),开发阶段最好关闭 --&gt;  
 &lt;constant name="struts.serve.static.browserCache" value="false" /&gt;

 &lt;!-- 开发模式下使用,这样可以打印出更详细的错误信息  
 &lt;constant name="struts.devMode" value="true" /&gt; --&gt;  
 &lt;constant name="struts.devMode" value="false" /&gt;  
   
 &lt;!-- 上传的文件存放目录 --&gt;  
 &lt;constant name="struts.multipart.saveDir" value="tmp"/&gt;  
   
   
 &lt;!-- 参数struts.multipart.maxSize 为文件尺寸   默认是2M，如果不进行配置上传超出2M，会抛出错误 --&gt;  
 &lt;constant name="struts.multipart.maxSize" value="2000000" /&gt;

 &lt;!-- 把action对象交给spring创建 --&gt;  
 &lt;constant name="struts.objectFactory" value="spring" /&gt;  
   
   
 &lt;!-- 如果不是用action作为扩展名，则需要在这个地方配置扩展名，否则映射不上 --&gt;  
 &lt;constant name="struts.action.extension" value="do" /&gt;  
 

 &lt;package name="material" namespace="/material" extends="struts-default"&gt;  
  &lt;action name="listMaterial" class="materialAction" method="getTypes" /&gt;  
  &lt;action name="listMaterialType" class="materialAction" method="listMaterialType" /&gt;  
  &lt;action name="addMaterialType" class="materialAction" method="addMaterialType" /&gt;  
  &lt;action name="delMaterial" class="materialAction" method="deleteMaterialType" /&gt;  
  &lt;action name="updateMaterial" class="materialAction" method="updateMaterialType" /&gt;  
  &lt;action name="getMaterialTypePath" class="materialAction" method="getMaterialTypePath" /&gt;  
  &lt;action name="findMaterial" class="materialAction" method="findMaterial" &gt;  
   &lt;result name="success" &gt;/page/material/materialFind.jsp&lt;/result&gt;  
  &lt;/action&gt;   
    
  &lt;action name="checkFileName" class="materialAction" method="checkFileName" /&gt;  
  &lt;action name="checkMaterial" class="materialAction" method="uploadMaterial" /&gt;  
  &lt;action name="toUploaldFile" class="materialAction" method="showUploaldMaterial" &gt;  
   &lt;result name="success"&gt;/page/material/add.jsp&lt;/result&gt;  
     
  &lt;/action&gt;  
    
    
 &lt;/package&gt;  
    
&lt;/struts&gt;

5.3 action的代码：

public class MaterialAction extends BaseActionSupport&lt;Object&gt; implements ServletRequestAware{  
 

  String tempPath = MATERIAL\_TEMP\_DIR + \_SEPARATOR + materialName;  
  File dstFile = new File(tempPath);  
    
  /\**  复制到临时文件夹内 \*/  
  int fileSize;  
  try {  
   fileSize = FileOperate.copyFile2FileSize(this.upload, dstFile);

 

｝

 

 

BaseActionSupport

 

package com.dvnchina.itv.advert.action;

import java.io.File;  
import java.io.IOException;  
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;  
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;  
import org.apache.commons.logging.LogFactory;  
import org.apache.struts2.ServletActionContext;  
import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper;

import com.dvnchina.itv.advert.utils.GenericsUtil;  
import com.opensymphony.xwork2.ActionSupport;

public class BaseActionSupport&lt;T&gt; extends ActionSupport{  
   
 private static final long serialVersionUID = 1510137542622373146L;  
   
 protected final Log log = LogFactory.getLog(getClass());  
   
 protected final static String SPE = File.separator;  
   
 /\**  
  * id主键  
  \*/  
 protected Long id;  
   
 /\**  
  * 多个id字符串，以"逗号"分割  
  \*/  
 protected String ids;  
   
 /\**  
  * 工程的contextPath  
  \*/  
 protected String contextPath;  
   
 /\**  
  * extJs的页号  
  \*/  
 protected int start;  
   
 /\**  
  * extJs的分页记录  
  \*/  
 protected int limit;  
   
 /\**  
  * 页号  
  \*/  
 protected int pageNo;  
   
 /\**  
  * 每页记录数  
  \*/  
 protected int pageSize;  
   
 /\**  
  * 表格查询参数  
  \*/  
 protected String query;  
   
   
 /\**  
  * json格式数据  
  \*/  
 protected String dataJson;  
   
 /\**  
  * 上传的文件  
  \*/  
 protected File upload;  
   
 /\**  
  * 上传文件类型属性  
  \*/  
 protected String uploadContentType;  
   
 /\**  
  * 上传的文件名  
  \*/  
 protected String uploadFileName;  
   
 @SuppressWarnings("unchecked")  
 protected Class clazz;

 @SuppressWarnings("unchecked")  
 protected Class getClazz() {  
  return clazz;  
 }  
   
 @SuppressWarnings("unchecked")  
 public BaseActionSupport() {  
  Class genericClass = GenericsUtil.getGenericClass(getClass());  
  clazz = genericClass;  
 }  
   
 /\**  
  * render Text  
  \*/  
 public void renderText(String content) {  
  try {  
   HttpServletResponse response = ServletActionContext.getResponse();  
   response.setContentType("text/plain");  
   response.setCharacterEncoding("UTF-8");  
   PrintWriter out = response.getWriter();  
   out.print(content);  
   out.flush();  
   out.close();  
     
  } catch (IOException e) {  
   log.error(e);  
  }  
 }

 /\**  
  * render HTML  
  \*/  
 public void renderHtml(String content) {  
  HttpServletResponse response = null;  
  PrintWriter out  = null;  
  try {  
   response = ServletActionContext.getResponse();  
   response.setContentType("text/html");  
   response.setCharacterEncoding("UTF-8");  
   out = response.getWriter();  
   out.print(content);  
   out.flush();  
  } catch (IOException e) {  
   log.error("输出提示信息时出现异常",e);  
  } finally{  
   if (out!=null) {  
    out.close();  
   }  
  }  
 }

 /\**  
  * render XML  
  \*/  
 public void renderXML(String content) {  
  try {  
   HttpServletResponse response = ServletActionContext.getResponse();  
   response.setContentType("text/xml");  
   response.setCharacterEncoding("UTF-8");  
   PrintWriter out = response.getWriter();  
   out.print(content);  
   out.flush();  
   out.close();  
     
  } catch (IOException e) {  
   log.error(e);  
  }  
 }

 /\**  
  * render json  
  \*/  
 public void renderJson(String content) {  
  try {  
   HttpServletResponse response = ServletActionContext.getResponse();  
   response.setContentType("text/json");  
   response.setCharacterEncoding("UTF-8");  
   PrintWriter out = response.getWriter();  
   out.print(content);  
   out.flush();  
   out.close();  
  } catch (IOException e) {  
   log.error(e.getMessage(), e);  
  }  
 }  
   
 public PrintWriter getWriter(String encoding) throws IOException{  
     HttpServletResponse response = ServletActionContext.getResponse();  
     response.setContentType("text/html");  
     response.setCharacterEncoding(encoding);  
     PrintWriter out = response.getWriter();  
     return out;  
 }

 /\**  
  * 取得request  
  * @return  
  \*/  
 public HttpServletRequest getRequest(){  
  HttpServletRequest request = ServletActionContext.getRequest();  
  return request;  
 }  
   
 /\**  
  * 取得MultipartRequest  
  * 上传文件使用  
  * @return  
  \*/  
 public MultiPartRequestWrapper getMutipartRequest(){  
  MultiPartRequestWrapper mulRequest = (MultiPartRequestWrapper) ServletActionContext.getRequest();  
  return mulRequest;  
 }  
   
 /\**  
  * get userName from session  
  \*/  
 public static String getUserNameFromSesssion() {  
  String name = (String) ServletActionContext.getRequest().getSession().getAttribute("username");  
  return name;  
    
 }  
   
 /\**  
  * get conf from configuration.properties  
  \*/  
 public static String getPropertiesValue(String key) {  
//  PropertiesUtil.init("configuration.properties");  
//  String value = PropertiesUtil.getProperty(key,"");  
//  return value;  
  return null;  
 }  
   
 /\**  
  * 页面跳转  
  \*/  
 public String forWard() throws Exception {  
  return SUCCESS;  
 }  
   
 /\**  
  * get project realPath  
  \*/  
 public String getRealPath() {  
  HttpServletRequest request = (HttpServletRequest) ServletActionContext.getRequest();  
  String path = request.getSession().getServletContext().getRealPath("/");  
  return path;  
 }  
   
 /\**  
  * 获取Response  
  * @return  
  \*/  
 public HttpServletResponse getResponse(){  
  HttpServletResponse response = ServletActionContext.getResponse();  
  return response;  
 }

 public String getContextPath() {  
  return contextPath;  
 }

 public void setContextPath(String contextPath) {  
  this.contextPath = contextPath;  
 }

 public void setQuery(String query) {  
  this.query = query;  
 }

 public Long getId() {  
  return id;  
 }

 public void setId(Long id) {  
  this.id = id;  
 }

   
 public int getStart() {  
  return start;  
 }

 public void setStart(int start) {  
  this.start = start;  
 }

 public int getLimit() {  
  return limit;  
 }

 public void setLimit(int limit) {  
  this.limit = limit;  
 }

 public String getDataJson() {  
  return dataJson;  
 }

 public void setDataJson(String dataJson) {  
  this.dataJson = dataJson;  
 }

 public String getIds() {  
  return ids;  
 }

 public void setIds(String ids) {  
  this.ids = ids;  
 }

 public File getUpload() {  
  return upload;  
 }

 public void setUpload(File upload) {  
  this.upload = upload;  
 }

 public String getUploadContentType() {  
  return uploadContentType;  
 }

 public void setUploadContentType(String uploadContentType) {  
  this.uploadContentType = uploadContentType;  
 }

 public String getUploadFileName() {  
  return uploadFileName;  
 }

 public void setUploadFileName(String uploadFileName) {  
  this.uploadFileName = uploadFileName;  
 }  
}