What is servlet and the superiority of servlet

xiaoxiao2021-03-06  15

Servlet is a Server-end program written in Java, which is independent of the protocol and platform. Servlet runs in Java-enabled Web Server. Java Servlets can dynamically extend Server's capabilities and use request-response mode to provide web services. The earliest support of servlet technology is Java Web Server for Javasoft. Thereafter, some other Java-based Web Server begin to support standard servlet APIs. The main feature of the servlet is interactively browsing and modifying data, generating dynamic web content. This process is: the client sends a request to the server side; the server sends the request information to the servlet servlet to generate the response content and pass it to the server. Response content dynamically generated, typically depending on the client's request server to return to the client servlet as a usual Java program. Servlet imports a specific package that belongs to the Java Servlet API. Because it is an object word code, you can load from the network, you can say that servlet is just like Applets, however, due to servlets running in Server, they do not need a graphical user interface. From this perspective, servlet is also known as Faceless Object. Java Servlet Advantages: Servlets can interact with other resources (files, databases, applets, java applications, etc.) to generate response to the client. You can also save the information during the response if needed. With servlet, the server can fully authorize access to local resources (such as database), and servlet itself will control external users access quantity and access nature servlets can be client programs for other services, for example, they can be used for distributed In the application system, the servlet can be activated from the remote hard drive from the remote hard drive from the local hard drive. The servlet can be linked (chain). A servlet can call another or a series of servlets, which becomes its client. With Servlet TAG technology, you can dynamically call servlets in the HTML page. The Servlet API has nothing to do with the agreement. It does not have any assumptions to delivering its protocol. Like all Java programs, servlet has all the advantages of object-oriented Java language servlet, providing all the advantages of Java applications - portable, robust, easy development. Using the Servlet's TAG technology, servlet can generate dynamic content embedded in a static HTML page. A servlet is activated by the first request sent by the client, and then it will continue to run in the background, waiting for future request. Each request will generate a new thread instead of a complete process. Multiple customers can get services at the same time. In general, the servlet process is only uninstalled when the Web Server is uninstalled. Servlet lifecycle: load servlet. This operation is generally dynamically performed. However, Server usually provides an option to force load and initialize a specific servlet when Server starts.

Server Create a Server Call Server Call Servlet's init () method A client's request to Server Server Creating a request object server Creating a service () method for the response object Server to activate the Servlet () method, transfer request and response object as a parameter service () method Get information on request objects, processing requests, access to other resources, and obtain the required information service () method using the method of responding to the server, and finally reaches the client. The service () method may activate other methods to process requests, such as doget () or dopost () or new methods developed by the programmer for more client requests, Server creates new requests and responding objects, still activation this servlet The service () method, passes the two objects as a parameter to it. Such cycles are repeated, but no need to call the init () method again. General servlets only initialize once, when Server does not need servlet (usually when Server is closed), Server calls the servlet's Destroy () method. In the United States, EJB Servlet JSP is almost developing standards for e-commerce. Original ASP is also very promising, but Microsoft may focus on the lawsuits and WIN2000, so e-commerce has developed too little. PHP does not hope because of its model and some natural defects. In the United States, there are very few commercial sites with PHP. Servlet development initial

Servlet is an application technology in the Java language in the web server, and future servlets will thoroughly replace CGI. This lecture will specifically introduce the concept, development, commissioning, and corresponding application examples of servlets. First, what is servlet? · Servlet is a Java application that is independent of the server-side of the platform and protocol, which can generate a dynamic web page. · Servlet is a Java application located within the server side within the web server. Unlike the traditional Java application launched from the command line, the servlet is loaded by the web server, which must contain Java virtual machines that support servlet. • The relationship between servlet and web server is similar to the relationship between Applet and web browsers (this is why servlet technology is called servlet), we can imagine servlets to do not have an APPLET without front-end interface (Faceless). Unlike Applets, because servlet runs in the web server side, it is a trusted program that is not limited by Java security, with the same permissions as ordinary Java applications. · Servlet is an alternative technology for CGI Script, because servlet has a significant advantage over the performance, portability, code reuse, etc., so servlets may completely replace CGI during future technology development. 2. Writing the development environment required by servlets for servlet development is JSDK and a web server that supports servlet. 1.jsdk (Java Servlet Development Kit) JSDK contains the Java class libraries that compile the Servlet application and related documents. For users developed using Java 1.1, JSDK must be installed. JSDK has been integrated into the Java 1.2 Beta, so if you develop using Java 1.2, you don't have to install JSDK. JSDK can download free download of Javasoft's site, its address is http://jserv.javasoft.com/products/java-server/downloads/index.html 2. Support Servlet Web Servlet needs to run a web server that supports servlet on. Currently supporting the WEB server of Servlet to push Sun's Java Web Server. If the existing web server does not support servlet, you can use some third-party manufacturers' server add-up (add-ons) to enable the web server to support servlet, where Live Software (http://www.livesoftware) is available. A product called JRUN allows Microsoft IIS and Netscape Web Server to support servlet by installing the corresponding version of JRUN. Third, the process of developing a servlet This article will describe the process of developing a servlet as an example of writing a simple servlet (we call Helloservlet). 1. Write a servlet code Java Servlet API is a standard Java extension package that contains two packages :javax.servlets and javax.servlet.http. For developers who want to develop customer-defined protocols, you should use the class and interface in the Javax.Servlet package; for developers with the HTTP protocol to interact with the client, just need to use javax.servlet.http package The class can be developed with the interface.

Below is a typical servlet program code: import javax.servlet. *; Import javax.servlet.http. *; Import java.io. *; import java.util. *; Public class helloservlet Extends httpservlet {public void Init ( ServletConfig config) throws ServletException {super.init (config);} public void service (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {String clientIPAddress = req.getRemoteAddr (); res.setContentType ( "text / html"); ServletOutputStream OUT = Res. GetOutputStream (); out.println (""); out.println (" Hello World </ title> </ head>"); Out.println ("<body" > "); OUT.PRINTLN (" <H1> Hello, You Come from " Clientipaddress " </ h1> "); Out.println (" </ Body> </ HTML> ");}} The servlet is implemented as follows : When the user accesses the servlet through the browser, the servlet returns an HTML page to the client browser: Hello, You com 192.168.0.11 where the client IP address is the client IP address. The main points of the program code are as follows: • Servlets based on the HTTP protocol must introduce Javax.Servlet and Javax.Servlet.http packages; · Helloservlets are derived from class httpservlets, HTTPSERVLET is a derived class of GenericServlet, and implements the servlet interface through the GenericServlet. HTTPSERVLET provides basic support for servlets based on HTTP protocol; service () method is the entry point of the servlet program. When the user calls the servlet from the browser, the servlet will enter the method. Service () contains two parameters, the HTTPServletRequest object contains information of the client request, which can obtain some information of the client (eg the IP address, browser type, etc.) and HTTP request type (for example, Get, Head, POST, PUT) through this parameter. Wait); HTTPSERVLETRESPONSE object is used to complete the interaction of servlet and client, and send an HTML page to the client by calling httpservletresponse.getoutputStream () customers to obtain the output stream to the client.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-45848.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="45848" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.037</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'nRrUyEd5LJ4F9CcDB73RCLBlEzmpsK60lrNyH1zqLX4MM1q2wwjStRm6mOafdrkGjn2Vo393EdouxK2ECco6Cg_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>