package com.servlet; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.jspsmart.upload.File; import com.jspsmart.upload.SmartUpload; import com.jspsmart.upload.SmartUploadException; public class UploadServlet extends HttpServlet { /** * Constructor of the object. */ public UploadServlet() { super(); } /** * Destruction of the servlet. <br> */ public void destroy() { super.destroy(); // Just puts "destroy" string in log // Put your code here } /** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out .println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); SmartUpload su=new SmartUpload(); su.initialize(this.getServletConfig(),request,response); su.setAllowedFilesList("doc,txt"); try { su.upload(); String name=su.getRequest().getParameter("username"); System.out.println(name); for(int i=0;i<su.getFiles().getCount();i++){ File file=su.getFiles().getFile(i); file.saveAs("/upfile/"+file.getFileName()); } //su.save("/upfile"); out.println("ok"); } catch (Exception e) { out.println("error"); } out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); } /** * Initialization of the servlet. <br> * * @throws ServletException if an error occure */ public void init() throws ServletException { // Put your code here } }

jameshkj LV8
2023年5月18日
lironggang LV38
2022年11月20日
15185836794 LV2
2021年11月8日
chenynhz LV2
2021年9月16日
1126055836 LV15
2021年8月20日
isMrQt LV1
2021年7月15日
15630419308 LV2
2021年5月16日
keeeww LV1
2020年11月20日
小仙女本仙haha LV8
2020年6月20日
lyd19931203 LV21
2020年6月16日