Java web part, java development back-end development interview questions

java web java development back-end

1、http Request process for ?


①:DNS Domain name resolution IP Address

②: The client establishes a connection with the server (TCP Three handshakes )

③: Client initiates request

④: The server received the request according to the port number . Find the corresponding resource file , Respond to the source code to the client

⑤: The client gets the requested data (html The source code of the page ), Start parsing the page and requesting resources

⑥: Client render page

⑦:web Server Disconnected ( Four waves )

2、http Requested GET And POST Differences in methods


Form Medium get and post Method , In the process of data transmission, they correspond to http Agreed GET and POST Method . The main differences between the two are as follows :

(1)Get It's used to get data from the server , and Post It is used to transfer data to the server ;

(2)Get Set the data in the form according to the variable=value In the form of , Add to action The point is URL Back , And both use “?” Connect , And the variables use “&” Connect ;Post Put the data in the form form In the data body of , In the way that variables and values correspond , Pass on to action Points to URL;

(3)Get It's not safe , Because in the transmission process , Data is placed in the requested URL in ;Post All operations of are invisible to the user ;

(4)Get The amount of data transmitted is small , This is mainly due to URL Length limit ; and Post Can transfer a large amount of data , So you can only use Post;

(5)Get Limit Form The data set of the form must be ASCII character , and Post Support the whole ISO10646 Character set ;

(6)Get yes form The default method for .

3、 Explain what is servlet?


Servlet Is a platform and protocol independent server side Java technology , Can be used to generate dynamic Web page . With the traditional CGI( Computer graphic interface ) Like many others CGI Technical comparison ,Servlet Better portability 、 More powerful features , Less investment , Higher efficiency , Better security, etc .

Servlet It's using Java Servlet Application program interface (API) And related classes and methods Java Program .Java What language can do ,Servlet Basically, it can be done ( In addition to the graphical interface ).Servlet It is mainly used to process the client sent Http request , And return a response . What is usually said Servlet Is refers to HttpServlet, Used for processing Http request , The requests it can handle are doGet()、doPost()、service() Other methods . Developing Servlet when , Can inherit directly javax.servlet.http.HttpServlet.Servlet Need to be in web.xml To describe , for example : Mapping execution Servlet Name , To configure Servlet class 、 Initialize parameters , Make security configuration 、URL Mapping and setting startup priorities, etc .Servlet Not only can you generate HTML Script output , You can also generate binary form output .

Servlet It has a wide range of applications , We now use many popular framework technologies , Its most basic code is inseparable from

Servelt Support for . Like what I'm familiar with SSH frame ,Spring When container starts , To be in web.xml Medium load Spring Container of ActionContext Class to initialize Spring Some parameters of , Such as dependency injection 、 Mapping of database tables 、 Initialize the security configuration settings of the system read Properties and other related operations .

4、 say servlet Life cycle of ?


servlet There is a good definition of survival time , Including loading and instantiation 、 initialization 、 Processing requests and end of service . This lifetime is determined by javax.servlet.Servlet Interface init,service and destroy Method expression .

servlet After being instantiated by the server , The container runs its init Method , Run the request when it arrives service Method ,service Method to automatically dispatch the corresponding doXXX Method (doGet,doPost) etc. , Call the instance when the server decides to destroy it destroy Method .

web Container loading servlet, Life cycle begins . By calling servlet Of init() methods servlet The initialization . By calling service() Method realization , Call different... According to different requests do***() Method . End of service ,web Container call servlet Of destroy() Method .

5、Servlet Basic architecture


package test;

import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import

《 A big factory Java Analysis of interview questions + Back end development learning notes + The latest architecture explanation video + Practical project source code handout 》

【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 Full content open source sharing

javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class ServletName extends HttpServlet {

public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {

}

public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {

}

}

6、servlet API in forward() And redirect() The difference between ?


The former is only a turn of control in the container , The address after turning will not be displayed in the address bar of the client browser ; The latter is a complete jump , The browser will get the jump address , And resend the request link . such , You can see the link address after jump from the address bar of browser . therefore , The former is more efficient , When the former can meet the needs , As far as possible with forward() Method , also , It also helps to hide the actual links . In some cases , such as , You need to jump to a resource on another server , Must be used sendRedirect() Method .

7、Request Common methods of objects


setAttribute(String name,Object): Set name to name Of request Parameter values for

getAttribute(String name): Return from name

getCookies(): Return all of the client's Cookie object , The result is a Cookie Array

getCharacterEncoding(): Returns the encoding of characters in the request

getParameter(String name): Get the client to send to the server name Specified parameters

getRequestURI(): Get the address of the client that issued the request string

getRemoteAddr(): Get client's IP Address

getRemoteHost(): Get the name of the client

getServerName(): Get the name of the server

getServletPath(): Get the path of the script file requested by the client

getServerPort(): Get the port number of the server

removeAttribute(String name): Delete a property in the request

8、 sketch HttpSession The role of 、 Usage method , It can be explained by code


HttpSession User information can be tracked and stored in , Set values to properties , Yes 2 A way :setAttribute()、getAttribute();

for example : Use... In a method session.setAttribute(“student”,student); In a session Set a property named student, The value is a value called student The object of . And then in the same session Within the scope of getAttribute(“student”) Take out the attribute , obtain student object .

9、jsp What are the built-in objects ? What are the functions ? What's the way to separate ?


jsp There are the following 9 Built in objects :

request Client requests , This request will contain information from GET/POST Requested parameters

response The web page returns a response from the client

pageContext The properties of web pages are managed here

session Session related to the request

application servlet What is being done

out To transmit the output of a response

config servlet The frame components of

page JSP Web page itself

exception For the wrong page , Exceptions not caught

request: Express HttpServletRequest object . It contains information about browser requests , And several are provided for obtaining cookie, header, and session Useful methods of data .

response: Express HttpServletResponse object , And provides several settings for sending back Browser response method ( Such as cookies, Head information, etc )

out: The object is javax.jsp.JspWriter An example of , There are several ways that you can use to send back output to the browser .

pageContext: It means a javax.servlet.jsp.PageContext object . It is used to facilitate access to a wide range of namespace 、servlet Of related objects API, And packed the universal servlet Methods of related functions .

session: Represents a requested javax.servlet.http.HttpSession object .Session It can store the user's status information

applicaton : It means a javax.servle.ServletContext object . This helps to find out about servlet The engine and servlet Information about the environment

config: It means a javax.servlet.ServletConfig object . This object is used to access servlet Initialization parameters of the instance .

page: Represents a... Generated from this page servlet example

10、 Introduced in JSP How to use JavaBean?


stay JSP Use in JavaBean The common movements are :

<jsp:useBean />: Used to create and find bean object ;

<jsp:setProperty />: Used to set bean Properties of , That is to call it setXxx() Method ;

<jsp:getProperty />: Used to obtain bean Properties of , That is to call it getXxx() Method

11、JSP Common instructions for


isErrorPage( Can I use Exception object ),isELIgnored( Ignore expression )

12、jsp There are four ranges of ?


page Valid on the same page ;

request On the same request ( Request page ) Inter effective , The general request is invalid after it is completed , But if you pass forward The way to jump , be forward The page is still available request Value , But if it's through redirect The way , It is equivalent to sending a page request again ,request The value in is invalid ;

session Valid for the lifetime of a session , In short, it is the time of connecting to the server , Note that all pages share , If the line breaks during , It will be invalid ;

application The scope is the largest , It will not fail until the server stops , All pages share . However, it should not be defined too much , Otherwise, it may increase the burden on the server ;

13、jsp Scope from large to small


application> session> request> page

It is worth noting that one request It can contain more than one page(include, forward, filter)

14、 What is the function of the filter ?


Can verify whether the customer is from a trusted network , Data submitted by customers can be recoded , Configuration information can be obtained from the system , It can filter out some words of customers that should not appear , You can verify that the user is logged in , It can verify whether the client's browser supports the current application , Can record the system log and so on .

15、 Filter usage ?( Unified coding and authentication of client requests )


First of all, we should realize Filter Interface , Simultaneous coverage Filter Three methods of interface :

init(FilterConfig config)// Used to obtain FilterConfig object ;

doFilter(ServletRequest request,ServletResponse response,FilterChain chain)// Some businesses for filtering ;

destroy()// The destruction Filter.

16、JSP and Servlet How to implement request forwarding in ?

copyright:author[m0_ sixty-four million three hundred and eighty-four thousand t],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/01/202201261259545663.html