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
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
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- i want to call a child component method from a parent in vuejs
- xcode - pod install [!] no `podfile 'found in the project directory
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file