<!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>
$('#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;
}
}
#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
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
经典的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
本文链接
javascript中回退的前一页可以写为:
history.go(-1)
或
location.href = document.referrer;
二者的区别为:
前者回退到前一页时,前一页的请求信息和上次一样(referrer没有变),其实这才是真正的后退
后者回退到前一页时,前一页的referrer就是当前页面
本文链接