public class UploadServlet extends HttpServlet {
private static final String LINE_SEPARATOR ="\r\n";
/**
* 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 doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @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 doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
/**
* 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 {
String contentType = request.getContentType();
InputStream in1=request.getInputStream();
int offset = -1;
StringBuffer sb=new StringBuffer();
BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream("D:\\abc.zip"));
byte[] b=new byte[4096];
while((offset=in1.read(b,0,4096))>-1){
sb.append(new String(b,0,offset,"UTF-8"));
bos.write(b, 0, offset);
}
bos.flush();
bos.close();
}
public void init() throws ServletException {
// Put your code here
}