23,404
社区成员
发帖
与我相关
我的任务
分享
<form id="sjwh_dr_form" action="${basepath}jcxx/sjwh/dr.action" method="post" >
<table class="tableys_yu" width="100%" border="0" cellpadding="0" cellspacing="1" style="border-spacing:1;">
<tr>
<td colspan="5" align="center">
<h1>导入XML</h1>
</td>
</tr>
<tr>
<td colspan="5">
<input id="sjwh_file" name="uploadFile" type="file" />
<input type="submit" value="导入XML" />
</td>
</tr>
</table>
</form>
@RequestMapping(value="dr")
public String dr(HttpServletRequest request,HttpServletResponse response,String navTabId,String uploadFile){
InputStream is = null;
try {
is = request.getInputStream();
// is.reset();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
byte[]b=new byte[1024];
try {
is.read(b);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("is="+is.toString());
int i=uploadFile.lastIndexOf("\\");
uploadFile=uploadFile.substring(i+1, uploadFile.length());
// response.setContentType("multipart/form-data");
String message="";
// String fileName=uploadFile.getOriginalFilename();
// String path="C:\\"+fileName;
try {
FileUtils.copyInputStreamToFile(is, new File("C:\\", uploadFile));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
boolean isOK=sjwhServiceImpl.insertXML("C:\\"+uploadFile);
if(isOK){
message="导入成功!";
}else{
message="导入失败!";
}
File file=new File("C:\\"+uploadFile);
file.delete();
request.setAttribute("message",message);
return null;
}
@RequestMapping(value="dr")
public String dr(HttpServletRequest request,HttpServletResponse response,String navTabId,@RequestParam MultipartFile uploadFile){
String message="";
String fileName=uploadFile.getOriginalFilename();
String path="C:\\"+fileName;
try {
FileUtils.copyInputStreamToFile(uploadFile.getInputStream(), new File(path));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
message="导入失败!";
}
boolean isOK=sjwhServiceImpl.insertXML(path);
if(isOK){
message="导入成功!";
}else{
message="导入失败!";
}
File file=new File(path);
file.delete();
request.setAttribute("message",message);
return "forward:/pages/jcxx/sjwh/sjwh_liebiao.jsp";
}