版权声明:如需转载,请务必通知! https://blog.csdn.net/qq_39594542/article/details/85237677
上传文件:
${temp.proname} | ${temp.leix} | ${temp.pingpai} | ${temp.jiage} |
后台页面
@RequestMapping(“uploadfile”)
public String uploadfile(HttpServletRequest request,Model mo) throws IOException, ServletException {
Part part = request.getPart(“fileabc”);
String realPath = request.getServletContext().getRealPath("/");
String header=part.getHeader(“Content-Disposition”);
String filename = header.substring(header.indexOf(“filename=”") + 10, header.lastIndexOf("""));
part.write(realPath+ File.separator+filename);
BufferedReader bd = new BufferedReader(new InputStreamReader(new FileInputStream(realPath+"\"+filename),“GBK”));
StringBuffer sb = new StringBuffer();
String st = null;
while((st = bd.readLine())!=null){
System.out.println(st.toString());
ProductClass p = new ProductClass();
String[] split = st.toString().split(",");
p.setProname(split[0]);
p.setLeix(split[1]);
p.setPingpai(split[2]);
p.setJiage(Float.parseFloat(split[3]));
list.add(p);
}
mo.addAttribute("productlist",list);
return "product";
}