Servlet implements file download, servlet implements file
(1) The main directory of the project is as follows: (demonstrate the location of the image and servlet)
(2) The specific implementation code is as follows:
Package com. lc. httpTest; import java. io. fileInputStream; import java. io. IOException; import java. io. outputStream; import java. io. printWri
Servletconfig/servletcontext/servletrequest/servletresponseI. ServletConfig: Encapsulates the configuration information for the servlet and can obtain the ServletContext object.1 Getting initialization parametersA. Configuring initialization parameters B. Getting initialization parametersGetinitparamter (String name) gets the initialization parameters of the servlet-specified nameGe
//This is my first servlet, developed using the way the Servlet interface is implemented PackageCom.tsinghua;Importjavax.servlet.*;ImportJava.io.*;ImportJavax.servlet.Servlet;ImportJavax.servlet.ServletConfig;Importjavax.servlet.ServletException;Importjavax.servlet.ServletRequest;ImportJavax.servlet.ServletResponse;Importjava.io.IOException; Public classHelloImplementsservlet{/*** Method init * *@paramParm1
Servlet initializes and processes HTTP requests. servlet initializes requests.
The previous article details several core Servlet-related interfaces and classes. When we write Servlet classes by ourselves, we generally need to inherit the HttpServlet class to implement init (), doGet (), doPost (). When will the
[Servlet] how to compile a Servlet
Creating a Servlet through Eclipse or MyEclipse is simple, but we do not know what the relevant code means. Therefore, we need to study the generated code below.
First, let's look at the source code of the created Servlet File and find the following content:Is inherited from the HttpS
1, the foreground JSP code himily.jsp, defines the user name and the password two input box, uses the Post method to Submit:/order-web/himilyservlet where Order-web is the site name, Himilyservlet Access path for servlet@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="Utf-8"%>DOCTYPE HTML public "-//w3c//dtd HTML 4.01 transitional//en" "http://www.w3.org/TR/html4/loose.dtd ">HTML>Head>Metahttp-equiv= "content-type"content= "te
Knowing the role of the servlet, let's look at a servlet's program running an instance, why do you want to see the running instance? Because you want to run a servlet program successfully, you need to configure some files.
The writing of the servlet program
A servlet program that develops an HTTP request that can be
The servlet is not thread-safe, it runs its service method in a multithreaded manner, one instance can serve multiple requests, and its instances are generally not destroyed, so if there is only one servlet in your project, then the Web container will only create one instanceThe most intuitive thing to say about a servlet's container is to store and create something that maintains it, leaving the container,
After the Web container loads and instantiates the servlet, the servlet lifecycle begins and the container runs
Its Init method initializes the Servlet and runs its service method when the request arrives, service
Method automatically dispatch the corresponding Doxxx method (Doget,dopost) and so on, when the server determines
The Destroy method is called when
Servlet call process, servlet call
(1) enter the address in the browser. The browser first searches for the hosts file and translates the host name into an IP address. If the host name cannot be found, the browser then queries the dns server and translates the host name into an IP address.
(2) the browser accesses the server based on the IP address and port number, and organizes http request information t
Several key points of Servlet and several key points of servlet1. ServletConfig
ServletConfig is the Servlet configuration file. Corresponds to the
Its APIs include:
String getServletName (); // get the content in ServletContext getServletContext (); // get the Servlet context objectString getInitParameter (String name) // obtain the value of the specified initi
Write today based on the servlet and JSP and uploadify asynchronous file upload, the results of the control file upload Uploadservlet class is always unable to run, has been reported 404 Not Found, the console will also throw a servlet class ClassNotFound exception. I wrote a simple test servlet that could not be easily tested, either by Web.xml configuration or
1. When the servlet is called for the first time, it triggers the init function, which loads the servlet into memory. The INIT function will only be called once
2. Call the service function
3. The service function is called directly by any request that calls the servlet thereafter
4. When this web app reload or shuts down, the Destory function is called to des
Servlet File Upload and Servlet File Upload
Note:
The form method attribute should be setPOSTMethod. You cannot use the GET method.
The form enctype attribute should be setMultipart/form-data
The following example is implemented using commons-fileupload and commons-io packages.
Import java. io. *; import java. util. *; import javax. servlet. servletConf
Servlet BASICS (1): servlet Basics
I haven't looked at servlet for nearly a month, and I haven't gone deep into my first study. I just read it all in a general sense. After compiling some basic cases, I feel like I have never learned it. Here, I will take a moment to sort out these foundations, deepen my impressions and prepare for future quick review. After all,
JSP/Servlet ----- differences between charset and pageEncoding, and between jsp and servlet
I. Functions of several encodings in JSP/ServletIn JSP/Servlet, encoding can be set in four places (as shown below). The first two can only be used in JSP, and the last two can be used in JSP and Servlet.1. pageEncoding = "UTF-8
Servlet data cache and servlet Cache
Caching is a necessary way to improve data access capabilities and reduce server pressure. Today I want to talk about two data caching methods, 1 --> session caches data on a single data access interface page. 2 --> Singleton mode caches public data on the entire servlet page. 3 --> cookie local cache
1. What is cache?
What is
The life cycle of a Servlet:Instantiate, initialize, provide services, destroy instancesAfter the Web container loads the servlet and instantiates it, the servlet life cycle begins, the container runs its Init method for the servlet initialization, the request arrives to run its service method, and the service method automatically dispatches the run to the reques
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.