1. How do I change the Tomcat access port? Answer: conf/server.xml

2. How to configure tomcat Manager access users? Answer: conf/tomcat-users. XML is mainly used for debugging management. This function must be disabled in the online system

3, Three ways to publish projects to Tomcat Configure the virtual directory. 1) Copy the website directory to Tomcat /webapps (war zip package) 2) Configure the website directory in conf/server. XML 3) Create Catalina directory in independent configuration file conf Create a host directory under Catalina. Create XML under Catalina.

4. How to configure a virtual host in Tomcat? Answer: 1) in the conf/server. The XML configuration 2) modify the c: / Windows/system32 / drivers/etc/hosts file * configured hosts, in front of the line # 3) for the virtual host configuration ROOT (three ways)

5. How to handle the problem that the port is occupied during tomcat startup? 2) Fport check which port is occupied (DOS command) netstat /ano taskList 3) Shut down by task Management (Windows server HTTPD) —– Task manager fails to stop the service. Stop the service through service management

6. Servlet lifecycle Init (ServletConfig) service (ServletRequest, ServletResponse) destroy what time these three methods to perform the init default first visit, Load Servlet call (configuration changes load with server startup) service Each HTTP request, called —- multithreaded call mode destroy is called when the server stops

1) Class extends HttpServlet 2) overwrites doGet and doPost (if the code logic is the same, call each other) 3) configure web.xml

8, doGet, doPost relationship between service and doGet HttpServlet overrides the Service methods, calling the corresponding doGet and doPost based on page requests

9, Why is it recommended to override init(ServletConfig) instead of init(ServletConfig)? Parameterized init performs some operations on ServletConfig, calling no-parameter init in the parameterized init method. To simplify programming, override no-parameter init directly

What is the difference between ServletConfig and ServletContext? ServletConfig provides some initialization parameter information for each Servlet. ServletContext creates only one instance for each Web application. It can share data among multiple Web resources, provide initialization information for the entire Web application, and provide request distribution methods

Answer: In JavaWeb development, forwarding and redirection are resource access, forwarding is carried out inside the server, only a request and a response, the client path will not change, forwarding can only access the internal resources of the site. Redirect Based on two requests and two responses, the server tells the client to redirect to a resource, the client path changes, Redirect can also be directed to this site external resource request. GetRequestDispatcher. Forward response. SendRedirect development in the application: Redirects can be used anywhere (within the site) and must be used when you need to pass data by request (request.setattribute)

Answer: 200 Normal 302 Redirection 304 Cache 404 Not found 500 Server error

Answer: Through request.getheader (referer)

Answer: Response. setDateHeader(expires, milliseconds); Expiration Time Ms value: current time + how long to expire

What is the difference between setCharacterEncoding and setContentType in response SetCharacterEncoding Sets the character encoding in the response, but does not inform the client that setContentType is used to set the type of data file to be sent to the client. It also specifies the encoding format and the browser will view the file according to the specified encoding format

16, write a download Servlet, download the Chinese name of the text file note? Answer: Text files are the type supported by browsers, response.setHeader(Content-Disposition,attachment; filename=xxx); If the filename is Chinese, you need to encode the Chinese filename URLEncoder when filename= XXX splices the filename

Why do you need verification code technology when registering? Answer: Prevent some malicious attacks

18. How to solve the problem of garbled data submitted by users Post – request. SetCharacterEncoding get – manual transcoding URL/new String, modify tomcat default decoding URIEncoding = XXX

19, http://url? Name =zhangsan+lisi ———- Obtain the result using request.getParameter(name) Answer: zhangsan lisi

20, What does isCommitted mean? When true, which of the following methods can be performed: IsCommited is used to check whether the response output reaches the client. If the value is true, the forward redirect cannot be performed. You can perform include operations

Answer: HTTP protocol itself is stateless, the server to manage the client state, Cookie and Session two management client state technologies

2. The principle of Cookie technology? Answer: 1) The client accesses server resources 2) The server writes a Cookie (response) to the client —- Contains the Cookie header in the HTTP response 3) After the client receives the Cookie from the server, 4) The client will automatically carry the cookie information when it accesses the server next time

3. Cookie life cycle? Answer: The default Cookie is the session Cookie, when the session ends (browser closes) Cookie clearing If the Cookie maxAge is set, the Cookie expiration time will be calculated according to the set time. When the Cookie expires, the browser will clear the Cookie

Answer: Session Cookie in memory, persistent Cookie in hard disk

5. What are first-party cookies and third-party cookies Answer: first-party Cookie: access A generates A Cookie Third-party Cookie: access A generates B Cookie

Answer: The Cookie information is saved to the client, and the Session information is saved to the server. The Session technology is implemented based on cookies, and the Session id is written back to the client in the form of cookies

7. The life cycle of a Session (when a Session is created and destroyed) Session: 1) The server shuts down 2) the session expires (the server expires) 3) session.invalidate The session expiration. 1) session. SetMaxInactiveInterval (seconds) 2) configuration web. XML unit is minutes

Answer: Create a separate Session object for each Session, and each object has a unique Session ID. The Session ID is written back to the client in the form of cookies, so as to complete the tracking of the Session object

If the cookie is not persistent, close the browser and destroy the cookie(Session ID) in the client memory, the server Session still exists!

Answer: URL rewrite

Session. removeAttribute and session.invalidate RemoveAttribute removes data from the current session, and invalidate destroys the current session object, removing all data from it

Answer: When the client form is generated, a unique identifier (token) is generated, and the village token is kept in the session and hidden elements of the form. When the form is submitted, the token number of the form is taken out and compared with the token number in the session. If the form is consistent, the form submission is valid. After the session token is used once, it is cleared.

Answer: When the verification code is generated, the verification code is saved to the session. After the user submits the verification code, it is compared with the session

14, JSP operation principle? Answer: When JSP is accessed, the server (Tomcat) is loaded first, translated into the corresponding Servlet program by the server, compiled and executed

15. What is the difference between JSP and Servlet? Answer: JSP is translated into Servlet execution, Servlet is a Java program, Java code is more convenient, JSP support HTML syntax, so mainly used to produce dynamic web pages.

What are the nine built-in objects for JSP? Answer: page request session application response pageContext out config exception

Answer: Page Request session Application

Answer: Out output to the browser, based on response.getWriter. However, out and Response. getWriter have separate cache areas. When output content to the browser, response.getWriter content is output first, and then output out content

19, how to set up web project error friendly page ErrorPage: 1, JSP internal through errorPage isErrorPage configuration 2, in web. XML configuration set errorPage JSP internal errorPage can only solve 500 errors, web. XML also solve 404 errors

20, include directive and JSP :include difference Answer: include directive static introduction, in JSP source code stage introduction, after the introduction of complete translation process JSP :include dynamic introduction, in the program running, the introduction of target resources, the introduction of target resources running results