1. Print the content on the webpage:
Printwriter out = response. getwriter ();
Out. println ("<br/> ");
2. Modify the value in Tomcat. when accessing a directory, it is expanded in the form of a list.
The default servlet is in Tomcat/CONF/Web. xml
<Servlet>
<Servlet-Name> default </servlet-Name>
<Servlet-class> org. Apache. Catalina. servlets. DefaultServlet </servlet-class>
<Init-param>
<Param-Name> debug </param-Name>
<Param-value> 0 </param-value>
</Init-param>
<Init-param>
<Param-Name> listings </param-Name>
<Param-value> false </param-value>
</Init-param>
<Load-on-startup> 1 </load-on-startup>
</Servlet>
<Servlet-mapping>
<Servlet-Name> default </servlet-Name>
<URL-pattern>/</url-pattern>
</Servlet-mapping>
* Set the listing value to true ---- All files in a directory are displayed in the list when accessing a directory.
3. Status?
HTTP Response
1. Status line: Protocol version, status code, and description
Informational 1xx (100-199): the request is not processed and further information is required.
Successful 2XX (200-299): The request is successfully processed.
Redirection 3xx (300-399): redirection. Further operations are required on the client (after the request is processed)
Client error 4xx (400-499): client error ---- resource access does not exist
Server Error 5xx (500-599): Server Error
200 everything OK
302 request redirection
* A asks B to borrow money, and B notifies a to borrow money from C (Client a B and client C represent server resources)
304 no modification, notifying the client to access the local cache
404 resource not found
500 Internal Server Error
2. Common Message Headers
Location: http://www.it315.org/index.jsp (used together with the 302 status code to specify the redirection address)
Server: Apache Tomcat (server type)
Content-encoding: gzip (the response content is encoded in gzip compression format)
Content-Length: 80 (Response length)
Content-language: ZH-CN (Response LANGUAGE)
Content-Type: text/html; charset = gb2312 (Response Character Set)
Last-modified: Tue, 11 Jul 2000 18:23:51 GMT (use cache policy with if-modified-since)
Refresh: 1; url = http://www.it315.org (automatic refresh, xxx seconds page Jump)
Content-Disposition: attachment; filename=aaa.zip (File Download)
Disable browser caching
Expires:-1
Cache-control: No-Cache
Pragma: No-Cache
Connection: Close/keep-alive Connection closed after response
Date: Tue, 11 Jul 2000 18:23:51 GMT Response Time
4. Set the encoding format for browser viewing
// Set the browser view encoding, which must be written before the output stream.
Response. setcontenttype ("text/html, charset = UTF-8 ");
5. Get the current timeCode:
// Current time in milliseconds
Long time1 = new date (). gettime (); // The first method obtains the current time.
Long time2 = system. currenttimemillis (); // method for obtaining the current time
6. Notify the browser to view the fixed resource code as a download.
// Read resources in a browser as a download
Response. setheader ("content-disposition", "attachment; filename =" + filename );
4. Download an object
// Read resources in a browser as a download
Response. setheader ("content-disposition", "attachment; filename =" + filename );
Compile File DownloadProgramFor Files recognized by the browser, add the header information in the form of attachments: Content-Disposition
Setcontenttype
Note: The file name. Do not include Chinese characters or spaces in the complete path of the file to be saved.