您现在的位置:首页 >> 前端 >> 内容

Jsp页面上传图片和缩略图查看

时间:2017/1/10 11:08:19 点击:

  核心提示:关于Jsp页面上传图片和缩略图查看主要分为两部分:第一,图片的上传,图片保存在ftp服务器里(也可以是对应的项目文件夹下需要相对应的修改)第二,上传后,我们通过点击页面的缩略图查看原图关于图片的上传操...

关于Jsp页面上传图片和缩略图查看

主要分为两部分:

第一,图片的上传,图片保存在ftp服务器里(也可以是对应的项目文件夹下需要相对应的修改)

第二,上传后,我们通过点击页面的缩略图查看原图

关于图片的上传操作:

1.在附件上传页面引入验证js:

<script type="text/JavaScript" src="../check.js"></script>//导入验证js

然后在我们的form表单中修改属性,新增附近上传元素

<s:form name="form1" action="/instancyCase/caseInfo!saveCaseInfo.action" method="post" enctype="multipart/form-data">  
  
      <tr>  
            <td class="table_rleft">附件:</td>  
           <td  colspan="3">  
           <input type="file" name="fj" id="fj"/>  
           <span style="font-size: 12px;color: red">  
           <s:property value="error"/> </span>  
        </td>  
     </tr>  
     <input type="submit" id="IsSubmit" class="button" name="update" value="  保存  " onmouseup="return UpCheck('fj')" />  
  
</s:form>

以上代码可直接拷到jsp中使用,部分属性改一下就行了。

2、Action层:

附件涉及的变量:

private String error;                       //错误信息提示属性  
  
private TblSpisCorpInstancyCaseFj ruleFj;   //自定义的附近pojo  
  
private File fj;                               //附件对象 

保存或者更新附件信息的方法体内填入以下代码:

if (fj != null){  
  
    String check = CheckFile.getFileByFile(fj);                    //主要是验证附件的格式,比如:jpg .gif .png .bmp等格式  
  
    if (check!=null&&!"".equals(check)) {  
  
        String tem_path = Util.FTP_FOLDER+File.separator+Util.WARD_PHOTO;  
  
        String xdpath = Util.FTP_FOLDER+File.separator+Util.WARD_PHOTO;  
  
  
  
        String file_Name = UploadFTP.copyFTP( this.getFj(),tem_path,"jpg",(sessionUser.getId()).toString());  
  
        ruleFj.setCorpInstancyCaseFjPath(xdpath + File.separator + (sessionUser.getId()).toString()+File.separator + file_Name );  
  
        ruleFj.setCorpInstancyCaseFjName(file_Name);  
  
        ruleFj.setCreateTime(new Timestamp(System.currentTimeMillis()));  
  
        ruleFj.setCorpInstancyCaseFjType("2");  
  
   }else{  
  
        this.setCaseObj(caseObj);  
  
        error= "文件格式不对";  
  
        return addCaseInfo();  
  
  }  
  
}  

缩略图查看原图

需要在Jsp查看附件页面新增:

<tr>  
  
    <td class="table_rleft">附件:</td>  
  
       <td  colspan="3"> 
    <s:if test=”ruleFj.corpInstancyCaseFjPath!=null”>  
  
     <img src="<%=basePath%>/JpgShow.jsp?path=${ruleFj.corpInstancyCaseFjPath }" width="100" height="75"/>  
  
    </s:if>  
  
    <s:else>  
  
       暂无附件信息  
  
    </s:else>  
  
</td>  
  
gt; 

Tags:JS SP P页 页面 
作者:网络 来源:K_Men的博客