struts2 不用标签文件上传 发现网上和书上都是带<s:file>的有没有不带的例子,请分享下,谢谢struts2 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果不用s的标签 那就用input type="file" 做上传一样的 网上很多 上传下载啊。自己搜啊。 什么ajax 上传,基于servlet上传。 不用标签也一样的呀index.jsp <body> <form action="uploadAction.action" method="post" enctype="multipart/form-data"> <input type="file" name="image"><br/> <input type="submit" value="上传"> </form> ${message} </body>UploadAction.javapublic class UploadAction extends ActionSupport { private File image; private String imageFileName; private String imageContentType; private String filePath; public String getFilePath() { return filePath; } public void setFilePath(String filePath) { this.filePath = filePath; } public File getImage() { return image; } public void setImage(File image) { this.image = image; } public String getImageFileName() { return imageFileName; } public void setImageFileName(String imageFileName) { this.imageFileName = imageFileName; } public String getImageContentType() { return imageContentType; } public void setImageContentType(String imageContentType) { this.imageContentType = imageContentType; } @Override public String execute() throws Exception { System.out.println("upload"); String realpath = ServletActionContext.getServletContext().getRealPath( "/images"); if (this.image != null) { File savefile = new File(new File(realpath), imageFileName); if (!savefile.getParentFile().exists()) savefile.getParentFile().mkdirs(); FileUtils.copyFile(image, savefile); this.filePath = "images/" + imageFileName; ActionContext.getContext().put("message", "文件上传成功"); } return UploadAction.SUCCESS; }} <s:form action="upload" enctype="multipart/form-data" method="post"> <s:textfield name="title" label="文件标题" /> <s:file name="upload" label="文件选择"/> <s:submit value="上传" /> </s:form> 其实用不用都一样,具体可以看看页面的input源代码,http://blog.csdn.net/chenghui0317/article/details/9531879 关于spring和ServletContextListener jboss6.0配置jms(主要是控制线程数量怎么配置) 项目发布问题? 服务器能否主动向web客户端发送信息! 遇到一个棘手的hibernate的效率问题 新手提问,如何根据规定好的SOAP请求和响应格式,发布此WebService 请教两个struts的简单问题,急!!! 一个关于转码的问题! 持久订阅问题 请高手指点一下,实体BEAN存在的价值. 请教大神itext怎么将现有的PDF转换缩放大小 excel导出中文,早linux部署下得到的为乱码,在window下没问题,求解决??
index.jsp <body>
<form action="uploadAction.action" method="post" enctype="multipart/form-data">
<input type="file" name="image"><br/>
<input type="submit" value="上传">
</form>
${message}
</body>UploadAction.javapublic class UploadAction extends ActionSupport {
private File image;
private String imageFileName;
private String imageContentType;
private String filePath;
public String getFilePath() {
return filePath;
} public void setFilePath(String filePath) {
this.filePath = filePath;
} public File getImage() {
return image;
} public void setImage(File image) {
this.image = image;
} public String getImageFileName() {
return imageFileName;
} public void setImageFileName(String imageFileName) {
this.imageFileName = imageFileName;
} public String getImageContentType() {
return imageContentType;
} public void setImageContentType(String imageContentType) {
this.imageContentType = imageContentType;
} @Override
public String execute() throws Exception {
System.out.println("upload");
String realpath = ServletActionContext.getServletContext().getRealPath(
"/images");
if (this.image != null) {
File savefile = new File(new File(realpath), imageFileName);
if (!savefile.getParentFile().exists())
savefile.getParentFile().mkdirs();
FileUtils.copyFile(image, savefile);
this.filePath = "images/" + imageFileName;
ActionContext.getContext().put("message", "文件上传成功");
}
return UploadAction.SUCCESS;
}
}
<s:textfield name="title" label="文件标题" />
<s:file name="upload" label="文件选择"/>
<s:submit value="上传" />
</s:form>