下面是jsp端接受数据页面代码:
- <%@ page language="java" contentType="text/html; charset=UTF-8"%>
- <%@ page import="java.util.*,java.io.*,com.itsv.cms.base.writer.PublishFileWriter;" %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html lang="true">
- <head>
- <title>upload.jsp</title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- </head>
- <%
- String fileName = request.getParameter("newfilename");
- String filePath = request.getRealPath("/")+"/uploadImg/"+fileName;
- System.out.println("start");
- //接收文件
- try {
- InputStream is=request.getInputStream();
- filePath=filePath.replaceAll("\\\\", "/");
- String f=filePath.substring(0,filePath.lastIndexOf("/"));
- PublishFileWriter.createPath(f);
- File file=new File(filePath);
- FileOutputStream fos = new FileOutputStream(file);
- int c;
- byte b[] = new byte[4*1024];
- while ((c=is.read(b))!=-1) {
- fos.write(b, 0, c);
- }
- fos.flush();
- is.close();
- }catch(Exception e){
- e.printStackTrace();
- }
- System.out.println("end");
- %>
- <body>
- This a struts page. <br>
- </body>
- </html>