Talk about servlet (1)

xiaoxiao2021-03-06  21

1. To introduce servlet.jar in Application with servlet

2. Then you have to be in the .java file

import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServlet; import javax.servlet.ServletException; import java.io.IOException; import java.io.PrintWriter; // This IMPORT can be introduced depending on the situation

3. Introduce several common methods in the servlet

a) Protected void service (httpservervetrequest req, httpservletResponse res) throws servletexception, ioException {}

If it is OverWrite, you may not call DOXXXMETHOD.

b) Protected void doget (httpservervetrequest req, httpservletResponse res) throws servletexception, ioException {}

Features 1: Safe and Idempotent. 2: Only Ascii (Text) Data Can Be Sent To Server with Get Method. 3: Easy to Bookmarks.

Main role: Get data, not change data

c) protected void dopost (httpservervetrequest req, httpservletResponse res) throws servletexception, oException {}

Features 1: NOT SAFE AND IDEMPOTENT. 2DISALLOW BOOKMARKS.

Main role: transmit Form Data, large quantity of data, often used in BBS, etc., can change data storage

There are some things to talk about next time.

转载请注明原文地址:https://www.9cbs.com/read-43210.html

New Post(0)