#getpost.py #This Servlet prints the Contents #of the POST data when a file is Uploaded from #the client using a HTML FORM #This helps in understanding how file uploads #take place from javax import servlet from javax.servlet import http from java.io import * from java.util import * from java.lang import * import string #Define Server IP address and Port number SERVER_IP = "127.0.0.1" SERVER_PORT = "8080" class getpost (http.HttpServlet): def doGet(self, req, res): #Send a File Upload Page to the client res.setContentType("text/html") toclient = res.getWriter() toclient.println( "
" """Enter the name of the File
""") def doPost (self, req, res): res.setContentType("text/html") toclient = res.getWriter() toclient.println("Printing Request Headers:

") names = req.getHeaderNames() #Get all header names while names.hasMoreElements(): #Get the value of each Header and send it #to the browser name =names.nextElement() values = req.getHeaders(name) if values!= None: while (values.hasMoreElements()): value = values.nextElement() toclient.println(name + ": " + value + "
") toclient.println("
Printing Stream contents:

") #Now printing the Stream contents input = BufferedReader(InputStreamReader(req.getInputStream())) read_data = input.readLine() #Print Start of the Stream header toclient.println("Start of Stream = ") toclient.println(read_data + "

") #Now print POST data while ( read_data != None ): toclient.println (read_data) last_read_line = read_data read_data = input.readLine() #Print end of Stream toclient.println ( "

End of Stream = " + last_read_line) #This is equal to the Start of stream header