Home>

A servlet is a java program written using the javaservlet application programming interface.It is derived from the request/response pattern.Can accept http requests from client browsers, generate a response and return to the client.

The difference and connection between applet jsp javabean and servlet

There is no main () method in applets and servlets, only some specific methods.Used to start execution and exit,But the servlet does not provide a user interface,Running on the server side,The applet provides a user interface,Runs on the client.

Both servlet and javabean are written in java, but javabean cannot run independently.It just provides an interface for jsp access, and the servlet can run independently.

Before the emergence of jsp,Sun company launched a servlet, but when using servlets to write html scripts, you need to print the output step by step using the print or println method.Bring a lot of trouble to development;Jsp web page is embedded java code in html script, which fundamentally changes the programming way

jsp javabean and servlet can communicate,For example:jsp can call javabean or servlet.After the servlet processes the data,It can be displayed through the jsp page.

All servlets directly or indirectly implement the javax.servlet.servlet interface

servlet life cycle:

Initialization When calling the init () method

When executed, when calling the service () method

At the end, when calling the destroy () method

web.xml writing method:

The first line<?xml version="1.0" encoding="iso-8859-1"?>describes the version and character set of the xml

The second line..............This is the main information of the xml

Name and customize url for servlet in xml

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
 xsi:schemalocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
 version="2.4">
<display-name>servlet technology</display-name>
<description>
 servlet instance
</description>
<servlet>
 <servlet-name>sampleservlet1</servlet-name>
 <servlet-class>ch7.sampleservlet1</servlet-class>
</servlet>
<servlet-mappint>
 <servlet-name>sampleservlet1</servlet-name>
 <url-pattern>/ch7/sampleservlet1</url-pattern>
</servlet-mappint>
</web-app>

Then enter in your browser:http://localhost:8080/myapp/sampleservlet1

jsp
  • Previous PHP file extension judgment and N ways to get file extension
  • Next C # rounded form simple implementation method