求一个使用struts完成上传的例子,注释一定要多 我的想法是这样,使用struts上传一份CSV文件,然后服务器端读取。然后进行持久化操作。我在网上搜了好多例子,搜到的多不能使用。。求一个完整的例子,要求简单,完整,注释多!~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 首先jsp页面<html> <head> <title>My JSP 'fileUpload.jsp' starting page</title> </head> <body> <form action="jdUpload" enctype="multipart/form-data" method="post"> 选择文件<input type="file" name="file"> <input type="submit" value="上传"> </form> </body> </html> 然后sturts,xml<package name="jingdong" namespace="/page/select/platform" extends="base"> <action name="jdUpload" method="upLoadFile" class="cn.magaseek.mj.select.controller.JdUpload"> <result name="success">/page/success.html</result> </action> </package>最后代码:public class JdUpload extends ActionSupport { private static final int FILE_SIZE=16*1024; private File file;//获取上传文件 private String fileName;//获取上传文件名称 private String fileContentType;//获取上传文件类型 public String upLoadFile(){ System.out.println("xxx"); String path = ServletActionContext.getServletContext().getRealPath("/file"); System.out.println(path); try { String name="FA-GE"; String fromjd="d://fromjd/"+name+".csv"; String logjd="d://logjd/"+name+".txt"; String cid_brand_file="d:\\cid_brand.txt"; long starttime=new Date().getTime(); long overtime = 0; //记录所有日志的str String str="运行开始\n"; //添加一件商品的完整流程的方法 AddItemAndOuterid add=new AddItemAndOuterid(); // 路径,品牌名,cid_预定品牌对照表 str=str+add.addItem(fileName,file,cid_brand_file); overtime=new Date().getTime(); str=str+"运行结束,运行时间为:"+(overtime-starttime); WriteHelper.writeToTxt(logjd,str); System.out.println("运行结束"); System.out.println("运行结束,运行时间为:"+(overtime-starttime)); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return "success"; } public File getFile() { return file; } public void setFile(File file) { this.file = file; } public String getFileName() { return fileName; } public void setFileName(String fileName) { this.fileName = fileName; } public String getFileContentType() { return fileContentType; } public void setFileContentType(String fileContentType) { this.fileContentType = fileContentType; } }这里获得的file就是所需要的file文件 给实体类的时间字段赋初始值 国际化web应用,在JSP页面中输出国际化信息,报错,请高手帮帮忙。 ssh DispatchiAction为null tomcat运行一段时间后程序就卡死,点击网页链接没有反应 java急需高手来请教~~ Spring mvc 页面接收数据的问题 急 请教下EJB QL的问题? 哪们兄弟给一份emf-sdo-runtime-2.0.0.zip包。官方下载一天没下来 高分寻求java界面编程书籍或类包 怎么将带struts标签的JSP页面转为一般JSP页面 java中的多线程 tomcat占用cpu很高
<html>
<head>
<title>My JSP 'fileUpload.jsp' starting page</title>
</head>
<body>
<form action="jdUpload" enctype="multipart/form-data" method="post">
选择文件<input type="file" name="file">
<input type="submit" value="上传">
</form>
</body>
</html>
然后sturts,xml
<package name="jingdong" namespace="/page/select/platform" extends="base">
<action name="jdUpload" method="upLoadFile" class="cn.magaseek.mj.select.controller.JdUpload">
<result name="success">/page/success.html</result>
</action>
</package>
最后代码:public class JdUpload extends ActionSupport {
private static final int FILE_SIZE=16*1024;
private File file;//获取上传文件
private String fileName;//获取上传文件名称
private String fileContentType;//获取上传文件类型
public String upLoadFile(){
System.out.println("xxx");
String path = ServletActionContext.getServletContext().getRealPath("/file");
System.out.println(path);
try {
String name="FA-GE";
String fromjd="d://fromjd/"+name+".csv";
String logjd="d://logjd/"+name+".txt";
String cid_brand_file="d:\\cid_brand.txt";
long starttime=new Date().getTime();
long overtime = 0;
//记录所有日志的str
String str="运行开始\n";
//添加一件商品的完整流程的方法
AddItemAndOuterid add=new AddItemAndOuterid();
// 路径,品牌名,cid_预定品牌对照表
str=str+add.addItem(fileName,file,cid_brand_file);
overtime=new Date().getTime();
str=str+"运行结束,运行时间为:"+(overtime-starttime);
WriteHelper.writeToTxt(logjd,str);
System.out.println("运行结束");
System.out.println("运行结束,运行时间为:"+(overtime-starttime));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "success";
} public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getFileContentType() {
return fileContentType;
}
public void setFileContentType(String fileContentType) {
this.fileContentType = fileContentType;
}
}这里获得的file就是所需要的file文件