当前位置:  编程技术>WEB前端
本页文章导读:
    ▪uploadify3.2+struts2文件上传      HTML页面 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8&qu.........
    ▪jQuery 弹出层菜单      经典的Jquery弹出层菜单,附完整代码。预览效果效果网址:http://www.keleyi.com/keleyi/phtml/divmenu.htm<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><.........
    ▪javascript 回退到前一页的写法及区别      javascript中回退的前一页可以写为:     history.go(-1)    或    location.href = document.referrer;    二者的区别为:    前者.........

[1]uploadify3.2+struts2文件上传
    来源: 互联网  发布时间: 2013-11-06
HTML页面
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<!-- 引入uploadify需要的css文件 -->
<link rel="stylesheet" type="text/css" href=/blog_article/"css/uploadify.css"/>/index.html
</head>
<body>    	    
    <!-- 上传按钮 -->    
    <input type="file" id="upload-button" />
    <!-- 上传 这里*也可以重写你需要的参数 -->
    <a href=/blog_article/"javascript_$/index.html('#upload-button').uploadify('upload','*')">开始上传</a>
    
<!-- 引入需要的JS文件 -->
<script type="text/javascript" src=/blog_article/"js/jquery-1.8.2.js"></script>/index.html
<script type="text/javascript" src=/blog_article/"js/jquery.uploadify.js"></script>/index.html
<script type="text/javascript" src=/blog_article/"js/upload.js"></script>/index.html
</body>
</html>

JS


$('#upload-button').uploadify({
      'width': '265',
      'height': '65',
      'buttonText': '上传图片',
      'auto': false, //不自动提交
      'swf': 'images/uploadify.swf',                      //falsh上传图片
      'uploader': 'upload.do',                                //上传处理,连接后台
      'fileTypeDesc': 'Supported File Format',     //文件类型描述
      'fileTypeExts': '*.jpg;*.jpge;*.gif;*.png',     //上传文件类型
      'fileSizeLimit': '10MB', //文件最大大小
      'fileObjName': 'file',  //后台接受文件对象名,保持一致
      'formData':{'id':1,'name':'irwin'}, //测试附加数据
      'onSelectError': function(file, errorCode, errorMsg){ //file选择失败后触发
          alert(errorMsg);
      },
      'onFallback': function(){ //flash报错触发
          alert("请您先安装flash控件");
      },
      'onUploadSuccess': function(file, data, response){ //上传成功后触发
          if("sizeError" == data){
              alert("文件大小不能超过10M");
          } else if("typeError" == data){
              alert("不支持的文件类型");
          }
      }
});

Struts代码,action
package com.rying.dms.web.action;

import java.io.File;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.rying.dms.util.UploadUtil;

public class UploadAction extends ActionSupport{
    private static Logger logger = Logger.getLogger(UploadAction.class);
    private static final long serialVersionUID = -3455411632907896807L;

    private File file;
    private String fileFileName;

    @Override
    public String execute(){
        PrintWriter out = null;
        try {
            HttpServletResponse response = ServletActionContext.getResponse();
            response.setContentType("text/html;charset=utf-8");
            out = response.getWriter();
           //test参数用来测试的路径名
           UploadUtil.upload("test", file, fileFileName);
        } catch (Exception e) {
            logger.error("upload files error",e);
            out.print(e.getMessage());
        }
        return null;
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public String getFileFileName() {
        return fileFileName;
    }

    public void setFileFileName(String fileFileName) {
        this.fileFileName = fileFileName;
    }

}


上传Util类代码,配置文件 配置文件:
#server path
docBase=D:\\upload

fileType=jpg,bmp,gif,png,jpeg,doc,pdf,exe,docx,avi,mp4,mp3,rmvb,3gp,swf
#the size is KB
maxSize=10240
#Thumbnail path
thumbnailPath=thumbnail
thumbnailWidth=100
thumbnailHeight=80


Util工具类:
package com.rying.dms.util;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.UUID;

import javax.imageio.ImageIO;

import org.apache.log4j.Logger;

import com.rying.dms.exception.UploadException;
import com.rying.dms.exception.UploadSizeException;
import com.rying.dms.exception.UploadTypeException;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

public class UploadUtil {
    private static Logger logger = Logger.getLogger(UploadUtil.class);
    
   //这里定义一些错误信息的常量
    private static final String SIZE_ERROR = "sizeError";
    private static final String TYPE_ERROR = "typeError";
    private static final String UPLOAD_ERROR = "uploadError";

    private static String maxSize;
    private static String fileType;
    private static String docBase;
    private static String thumbnailPath;
    private static String thumbnailWidth;
    private static String thumbnailHeight;

    /**
     * Upload file util
     *
     * @author Irwin.Ai
     * @throws UploadTypeException, UploadSizeException
     */
    public static void upload(String folderPath,File file, String fileName) throws UploadException, UploadTypeException, UploadSizeException {
        FileInputStream fis = null;
        FileOutputStream fos = null;

        try {
            //读取配置文件
            fis = new FileInputStream(Thread.currentThread().getContextClassLoader().getResource("/").getPath().replace("%20", " ") + "/upload.properties");
            Properties pro = new Properties();
            pro.load(fis);

            docBase = pro.getProperty("docBase");
            maxSize = pro.getProperty("maxSize");
            fileType = pro.getProperty("fileType");
            thumbnailPath = pro.getProperty("thumbnail");
            thumbnailWidth = pro.getProperty("thumbnailWidth");
            thumbnailHeight = pro.getProperty("thumbnailHeight");

            //验证文件类型
            String fileExt = "";
            // 获得文件扩展名
            if (fileName.lastIndexOf(".") >= 0) {
                fileExt = fileName.substring(fileName.lastIndexOf(".") + 1);
            }
            // 验证文件类型
            logger.info("file extend name = " + fileExt + ", support file type = " + fileType);
            if (("," + fileType.toLowerCase() + ",").indexOf("," + fileExt.toLowerCase() + ",") < 0) {
                logger.warn("文件类型错误");
		//类型验证错误,抛出异常,在action层捕获到,前台根据错误信息判断显示错误信息
                throw new UploadTypeException(TYPE_ERROR, new UploadTypeException());
            }

            //验证文件大小
            fis = new FileInputStream(file);
            Integer size = fis.available();
            logger.info("file size = " + (size / 1024) + ", max size = " + maxSize);
            if (size > Integer.parseInt(maxSize) * 1024) {
                logger.warn("文件大小不能超过10M");
                throw new UploadSizeException(SIZE_ERROR, new UploadSizeException());
            }

            //创建文件目录
            //重命名文件
            String newFileName = UUID.randomUUID().toString();
            //保存路径
            String saveDir = docBase + "/" + folderPath;
            //目录不存在则创建
            File fileDir = new File(saveDir);
            if (!fileDir.exists()) {
                fileDir.mkdirs();
            }

            //保存文件到服务器
            //文件保存路径
            String savePath = saveDir + "/" + newFileName + "." + fileExt;
            logger.info("save path = " + savePath);
            fos = new FileOutputStream(savePath);
            byte buffer[] = new byte[size];
            int len = 0;
            while ((len = fis.read(buffer)) > 0) {
                fos.write(buffer, 0, len);
            }

            //保存文件到数据库
            //--------------------------

        } catch (IOException e){
            logger.error(UPLOAD_ERROR, e);
            throw new UploadException(UPLOAD_ERROR, e);
        } finally {
            try {
                if(null != fos){
                    fos.flush();
                    fos.close();
                }
                if(null != fis){
                    fis.close();
                }
            } catch (IOException e) {
               logger.error("close stream error");
            }
        }

    }
    //创建缩略图
    public static void createThumbnail(File file, String fileExt)
            throws UploadException {
        try {
            Image img = ImageIO.read(file);
            BufferedImage image = new BufferedImage(
                    Integer.parseInt(thumbnailWidth),
                    Integer.parseInt(thumbnailHeight),
                    BufferedImage.TYPE_INT_RGB);
            image.getGraphics().drawImage(img, 0, 0,
                    Integer.parseInt(thumbnailWidth),
                    Integer.p      
    
[2]jQuery 弹出层菜单
    来源:    发布时间: 2013-11-06

经典的Jquery弹出层菜单,附完整代码。预览效果效果网址:http://www.keleyi.com/keleyi/phtml/divmenu.htm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>经典:柯乐义jQuery弹出层菜单</title><base target="_blank" />
<script type="text/javascript" src="http://www.keleyi.com/keleyi/pmedia/jquery-1.8.3.min.js"></script>
<style type="text/css">
body,h1,h2,h3,h4,h5,h6,p,ul,li,dl,dt,dd{padding:0;margin:0;}
li{list-style:none;}img{border:none;}em{font-style:normal;}
a{color:#555;text-decoration:none;outline:none;}
a:hover{color:#000;text-decoration:underline;}
body{font-size:12px;font-family:Arial,Verdana, Helvetica, sans-serif;word-break:break-all;word-wrap:break-word;}
.clear{height:0;overflow:hidden;clear:both;}
.keleyi_com{ margin:100px;}
.keleyi_com dl dt{width:70px;position:absolute; z-index:3;padding:0 5px;line-height:20px;}
.www_keleyi_com{border:#ccc 1px solid; border-bottom:none;background:#f1f1f1; margin:-1px 0 0 -1px;}
.keleyi_com dl dd{ width:110px;position:absolute;z-index:2;border:#ccc 1px solid;padding:5px; line-height:20px; background:#f1f1f1; display:none; margin:19px 0 0 -1px;}
.keleyi_com dl dd a{ display:block;border-bottom:#ccc 1px dashed;}
</style>
<script type="text/javascript">
$(document).ready(function () {
var objStr = ".keleyi_com";
$(objStr).each(function (i) {
$(this).mouseover(function () {
$($(objStr + " dd")[i]).show();
$($(objStr + " dt")[i]).addClass("www_keleyi_com");
});
$(this).hover(function () { }, function () {
$($(objStr + " dd")[i]).hide();
$($(objStr + " dt")[i]).removeClass("www_keleyi_com");
});
});
});
</script>
</head>
<body>
<!-- 【经典】柯乐义弹出层菜单 -->
<div >
<div >
<dl>
<dt><a href="http://www.keleyi.com">柯乐义菜单</a></dt>
<dd>
<a href="http://www.keleyi.com/menu/javascript/">Javascript</a>
<a href="http://www.keleyi.com/menu/jquery/">Jquery</a>
<a href="http://www.keleyi.com/menu/csharp/">C#</a>
<a href="http://www.keleyi.com/menu/net/">.NET</a>
</dd>
</dl>
</div><br /><br />请把光标移到上面菜单上<br /><br />
柯乐义提醒您:更多更新特效,请上www.keleyi.com
</div>
</body>
</html>

本文转载自柯乐义http://www.keleyi.com/a/bjac/b093dbeea725c30c.htm

本文链接


    
[3]javascript 回退到前一页的写法及区别
    来源:    发布时间: 2013-11-06

javascript中回退的前一页可以写为:

 

    history.go(-1)

    或

    location.href = document.referrer;

    二者的区别为:

    前者回退到前一页时,前一页的请求信息和上次一样(referrer没有变),其实这才是真正的后退

    后者回退到前一页时,前一页的referrer就是当前页面

本文链接


    
最新技术文章:
▪css white-space:nowrap属性用法(可以强制文字不...
▪IE里button设置border:none属性无效解决方法
▪border:none与border:0使用区别
▪html清除浮动的6种方法示例
▪三个不常见的 HTML5 实用新特性简介
▪css代码优化的12个技巧
▪低版本IE正常运行HTML5+CSS3网站的3种解决方案
▪CSS Hack大全-教你如何区分出IE6-IE10、FireFox、Chr...
▪ie6,ie7,ie8完美支持position:fixed的终极解决方案
▪小技巧处理div内容溢出
▪html小技巧之td,div标签里内容不换行
▪纯CSS实现鼠标放上去改变文字内容
▪li中插入img图片间有空隙的解决方案
▪CSS3中Transition属性详解以及示例分享
▪父div高度不能自适应子div高度的解决方案
▪告别AJAX实现无刷新提交表单
▪从零学CSS系列之文本属性
▪HTML 标签
▪CSS3+Js实现响应式导航条
▪CSS3实例分享之多重背景的实现(Multiple background...
▪用css截取字符的几种方法详解(css排版隐藏溢...
▪页面遮罩层,并且阻止页面body滚动。bootstrap...
▪CSS可以做的几个令你叹为观止的实例分享
▪详细分析css float 属性以及position:absolute 的区...
▪IE6/IE7/IE8/IE9中tbody的innerHTML不能赋值的完美解...
▪CSS小例子(只显示下划线的文本框,像文字一...
▪可以给img元素设置背景图
▪不通过JavaScript实现的自动滚动视差效果
▪div+CSS 兼容小摘
▪CSS的inherit与auto使用分析
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3