池塘

海阔天空任我游

What are Java Servlets?

   The Java Servlet API is an open standard,created by sun,for creating web applications using the Java programming language. A servlet is an object responsible for receiving a request from a client web browser and returning a response-an HTML page to be displayed in the browser.The Servlet API defines an interface and base class for servlets,as well as interfaces for several other supporting objects,such as the HttpServletRequest (which represents a request and allows the servlet to access query parameters).Vendors,both open source and proprietary,provide the actual server code and implementations of the standard interfaces.
    Servlets are most often paired with JavaServer Pages in order to generate a reponse.JSPs are a standard templating technology for servlets.A JSP is a mix of ordinary,static HTML with additional,specialized tags and directives that provide dynamic output,such as including the current user's name or the contents of an online shopping cart.Under the hood,each JSP is converted into a Java servlet that is compiled and loaded into memory.More information about servlets and JSPs is available online and in print ,including Web Development with JavaServer Pages.
    A servlet operates within a servlet container.The servlet container serves as a bridge between HTTP and the Java servlet code that you, as the developer ,will write.The servlet container is responsible for instantiating and initializing your servlets as needed.Servlet container s may be standalone,,such as Apache Tomcat,or may be one part of an  overall application server,such as BEA  WebLogic,IBM WebSphere ,or the open source JBoss application server.
    The servlet container is responsible for selecting the correct servlet to invoke based on the URL of the request;a single web application will contain many servlets.The web application's deployment descriptor gives the name and Java class for each servlet and identifies which URLs are mapped to which servlets.For example,your application may have a registration page containing an HTML form enabling new nsers to reggister .That form will submit to the addCustomer URL,which is mapped to the addCustomer servlet ,which is instantiated as the AddCustomerServlet class.The deployment descriptor will include the following elements describing the addCustomer servlet's configuration:
    <servlet>
       <servlet-name>addCustomer</servlet-name>
       <servlet-class>com.mycompany.AddCustomerServlet</servlet-classs>
    </servlet>
   
    <servlet-mapping>
       <servlet-name>addCustomer</servlet-name>
       <url-pattern>/addCustomer</url-pattern>
    </servlet-mapping>
    As can be seen from this example,each servlet represents a particular operation within the overall web application.The AddCustomerServlet class will include code that reads the query parameters submitted with form and uses those values to create some kind of Customer object that can be stored into a database.Additional logic must decide what form of response to display-normally a confirmation page,but possibly the originalpage containing the form if an error occurred when creating the customer.

阅读更多
个人分类: JAVA
上一篇Java Servlet API
下一篇Java的IO系统
想对作者说点什么? 我来说一句

Murach's Java Servlets and JSP, 3rd

2016年08月31日 37.71MB 下载

java servlets 编程指南

2008年10月09日 22.32MB 下载

没有更多推荐了,返回首页

关闭
关闭