做了一个实验,你可以使用这个东西:Jquery的插件 imgAreaSelectDownload the plugin, unzip it, and copy the JavaScript and CSS files to your website/application directory. Load the files in the <head> section of your HTML document. <head> ... <link rel="stylesheet" type="text/css" href="css/imgareaselect-default.css" /> <script type="text/javascript" src="scripts/jquery.min.js"></script> <script type="text/javascript" src="scripts/jquery.imgareaselect.pack.js"></script> ... </head> Then, to enable selection on an image, wrap it in a jQuery object and call the imgAreaSelect() method: <script type="text/javascript"> $(document).ready(function () { $('img#photo').imgAreaSelect({ handles: true, onSelectEnd: someFunction }); }); </script> 以上COPY From http://odyniec.net/projects/imgareaselect/
网上的东西不如书籍上面好,可以详细参见《Struts 2权威指南》 李刚的书,网上有该书的PDF书籍,而且我这里有这本书的所附光盘的源代码,把里面一小段文件上传看一下就ok了..你可以联系我,我给你发代码和书,关于文件上传这里面讲的异常透彻扣扣 40902零100
private String fileFileName;
private String fileContentType;
String url = "images\\ticket\\upload";
String path=ServletActionContext.getServletContext().getRealPath(url);
File f=new File(new File(path),time+"-"+fileFileName);
if(!f.getParentFile().exists()){
f.getParentFile().mkdirs();
}
FileUtils.copyFile(file,f);
ticket.setImage(url+"\\"+time+"-"+fileFileName);
}
ticketService.mergeTicket(ticket);
form 必须加和这个enctype="multipart/form-data"
做了一个实验,你可以使用这个东西:Jquery的插件 imgAreaSelectDownload the plugin, unzip it, and copy the JavaScript and CSS files to your website/application directory. Load the files in the <head> section of your HTML document.
<head>
...
<link rel="stylesheet" type="text/css" href="css/imgareaselect-default.css" />
<script type="text/javascript" src="scripts/jquery.min.js"></script>
<script type="text/javascript" src="scripts/jquery.imgareaselect.pack.js"></script>
...
</head>
Then, to enable selection on an image, wrap it in a jQuery object and call the imgAreaSelect() method:
<script type="text/javascript">
$(document).ready(function () {
$('img#photo').imgAreaSelect({
handles: true,
onSelectEnd: someFunction
});
});
</script>
以上COPY From http://odyniec.net/projects/imgareaselect/