struts2.3.4 注解 上传

批量上传

JSP 页面

<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
 String webcontent = request.getContextPath();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>JET欢迎你</title>
 </head>
<script type="text/javascript">

function addMore()
{
 var td = document.getElementById("more");
 var br = document.createElement("br");
 var input = document.createElement("input");
 var button = document.createElement("input");
 var span=document.createElement("span");
 input.type = "file";
 input.name = "upload";
 button.type = "button";
 button.value = "删除";
 
 button.onclick = function()
 {
  td.removeChild(br);
  td.removeChild(input);
  td.removeChild(button);
  td.removeChild(span);
 }
 input.οnchange=function(){
   clearTooltip(this);
   checkExt(this);
 }
 td.appendChild(br);
 td.appendChild(input);
 td.appendChild(span);
 td.appendChild(button);
 
}

</script>
 <body>
  <%--
  <form action="<%=webcontent %>/company/add.action" method="post">
   <input type="text" name="companyname" />
   <input type="submit" value="提交" />
  </form>
  --%>
  <s:form validate="true" method="post" theme="simple" enctype="multipart/form-data"
   action="/company/add.action">
   <table align="center" width="50%" border="1">
    <tr>
     <td align="left">公司名称</td>
     <td   align="left">
      <s:textfield name="company.company_name"
       maxlength="50"></s:textfield>
     </td>
    </tr>
    <tr>
     <td align="left" valign="top">上传文件</td>
     <td id="more">
      <s:file name="upload" οnchange="clearTooltip(this);checkExt(this);"></s:file>
      <span></span>
      <input type="button" value="添加多个" οnclick=addMore();>
     </td>
    </tr>
    <tr>
     <td colspan="2" align="right">
      <s:submit value="确定"></s:submit>
      <s:reset value="重置"></s:reset>
     </td>
     <s:token></s:token>
     <s:fielderror></s:fielderror>
    </tr>
   </table>
  </s:form>
 </body>
</html>

action
上传

@Action(value = "add", results = {
   @Result(name = "success", type = "redirect", location = "/company/findAll.action"),
   @Result(name = "input", location = "/company/companyAdd.jsp") }, interceptorRefs = {
   @InterceptorRef(value = "fileUploadStack"),
   @InterceptorRef(value = "defaultStack") }
)
 public String add() {
  String msg = "success";
  String upload_files = "";
  savePath = "/userfiles/images";
  if (upload.size() > 0) {
   try {
    upload_files = Imagesupload.imageup(getUploadContentType(),
      getSavePath(), getUpload());
   } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    message = "文件上传失败,类型不允许或文件大小受限!";
   }
  }
  try {
   company.setUpload_files(upload_files);
   companyService.add(company);
   message = "添加成功";
  } catch (Exception e) {
   message = "添加失败";
   e.printStackTrace();
  }
  return msg;
 }

 


下载用到的 注解

@Results( { @Result(name = "download", type = "stream", params = { "contentType", "application/vnd.ms-excel",
  "inputName", "inputStream", "contentDisposition", "attachment;filename=\"${downloadFileName}\"", "bufferSize",
  "4096" }) }) 



struts2.3.4.1+hibernate4.1.6+spring3.1.2 完整实例 : http://download.csdn.net/detail/sunsize1130/4698305
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值