Java web FAQs

Source: Internet
Author: User

1. How do I modify the Tomcat access port? Answer: CONF/server. xml

2. How to configure Tomcat Manager to access users? Answer: CONF/tomcat-users.xml main application debugging management, the function must be disabled in the online system

3. Three Methods for releasing a project to Tomcat: virtual directory configuration 1) copy the website directory to Tomcat/webapps (compress the website directory into a zip package of the war package) 2) configure CONF/server. configure <context Path = "" docbase = "/> 3) in XML

4. How do I configure a VM in Tomcat? Answer: 1) In CONF/server. xml configuration

5. How to Deal with answer when Tomcat is started: * multiple ports are required when Tomcat server is started. 1) check which port accounts for 8005. 2) fport: check which port is occupied (doscommand) netstat/ano tasklist 3) Close through Task Management (Windows Service httpd) ----- the Task Manager cannot close the service and stop the service through Service Management

6. servlet lifecycle answer: Init (servletconfig) Service (servletrequest, servletresponse) destroy when the init first access is executed by default, load servlet call (configure <load-on-startup> modify to load with server startup) Each HTTP request of the service, call ---- call when the destroy server stops using multi-thread call Method

7. Compile the servlet step answer: 1) Class extends httpservlet 2) overwrite doget and dopost (ifCodeThe logic is the same and calls each other) 3) Configure web. xml <servlet> <servlet-mapping>

8. Relationship between service and doget and dopost answer: the service servlet lifecycle is defined, while the implementation class httpservlet defines doget and dopost httpservlet to overwrite the service method, call doget and dopost Based on the page Request Method

9. Why is it recommended to overwrite the non-parameter init method, instead of the init (servletconfig) method answer: There is a parameter init to perform some operations on servletconfig, and the parameter init method calls the non-parameter init, to simplify programming, overwrite the non-parameter init

10. What is the difference between servletconfig and servletcontext? Answer: servletconfig provides initialization parameter information for each servlet. servletcontext creates only one instance for each web application and can share data among multiple web resources, provides initialization information for the entire web application and request distribution methods.

11. What is the difference between forwarding and redirection answer: in Java Web development, both forwarding and redirection are resource access methods, and forwarding is performed within the server, with only one request and one response, the client path will not change. forwarding can only access internal resources of the site. Based on two requests and two responses, the server notifies the client to redirect to a resource, the client path is changed, and the redirection can also be directed to the site's external resource request. getrequestdispatcher. forward response. applications in sendredirect development: You can use the redirection feature (in this site) to forward data. When you need to transmit data through a request (request. setattribute), must use forwarding

12. What are common status codes 200, 302, 304, 404, and 500? Answer: 200 normal 302 redirection 304 cache 404 cannot be found 500 Server Error

13. How to Prevent web page leeching answer: request. getheader ("Referer ")

14. How to set the expiration time of a webpage answer: Response. setdateheader ("expires", millisecond value); expiration time millisecond value: Current Time + how long has it expired?

15. What is the difference between setcharacterencoding and setcontenttype in response? Answer: setcharacterencoding sets the character encoding in the response, but does not notify the client that setcontenttype is used to set the type of the data file sent to the client, the browser will view the file according to the specified encoding format

16. What are precautions for downloading a Servlet and a text file with a Chinese name? Answer: text files are supported by browsers. setheader ("content-disposition", "attachment; filename = xxx"); if the file name is Chinese, urlencoder must encode the Chinese file name when filename = xxx is used to splice the file name

17. Why does the verification code technology be required for website login registration? Answer: prevents malicious attacks

18. How to Solve the Problem of garbled data when users submit requests answer: Post --- request. setcharacterencoding get ---- manually transcode the URL/New String, modify the default Tomcat decoding set uriencoding = xxx

19. http: // URL? Name = zhangsan + Lisi ---------- use request. getparameter ("name") to obtain answer: zhangsan Lisi

20. What is the meaning of iscommitted? If it is true, which of the following methods can be used to determine whether the response output content has arrived at the client, if it is true, forward redirect cannot be performed. You can perform the include operation.

1. Why use cookie and session technology answer: the HTTP protocol itself is stateless, and the server needs to manage the client status, Cookie and session.

2. How does cookie technology work? Answer: 1) the client accesses server resources. 2) The server specifies to write a cookie (response) to the client. The HTTP response contains the cookie header information. 3) after the client receives the cookie information returned by the server, saves the cookie in the browser memory by default (saves the cookie to the hard disk by setting the cookie in the maxage browser) 4) The client automatically carries the cookie information when accessing the server next time.

3. What is the cookie lifecycle? Answer: The default cookie is a session cookie. When the session ends (closed by the browser), if the cookie is set, maxage calculates the cookie expiration time based on the set time. When the cookie expires, the browser clears the cookie.

4. Differences between session cookie and persistent cookie answer: In the session cookie memory, in the persistent cookie Hard Disk

5. What is the first-party cookie and third-party cookie answer: First-party COOKIE: access a to generate a cookie, third-party COOKIE: access a to generate B cookie

6. Differences between session and cookie answer: cookie information is stored on the client, and session information is stored on the server. The session technology is implemented based on cookies and writes the session ID, which uniquely identifies the session, back to the client in the form of cookies.

7. Session lifecycle (when the session is created and destroyed) Answer: Creates the session: request. getsession destruction session: 1) server shutdown 2) session expiration (server expiration) 3) session. the invalidate session expiration time can be set in two ways: 1) session. setmaxinactiveinterval (seconds) 2) Configure web. XML <session-config> in minutes

8. Session implementation principle answer: Creates a separate session object for each session. Each object has a unique session ID. The session ID is written back to the client in the form of a cookie to track the complete session object.

9. Disable the browser to destroy the session answer. If the cookie is not persistent by default, disable the browser to destroy the cookie (session ID) in the client memory. The server session still exists!

10. Disable cookie so that the session cannot be used? Answer: URL rewriting

11. Differences between session. removeattribute and session. invalidate answer: removeattribute removes data from the current session. invalidate destroys the current session object and removes all data from it.

12. Prevent form refresh protection principle (token mechanism) answer: a unique identifier (token) is generated when the client form is generated, and the village token is saved to the session and form hidden elements, when the form is submitted, retrieve the order number of the form and compare it with the order number in the session. If the order number is the same, the form submission is valid. After the session number is used once, it is cleared.

13. Principle of one-time verification code answer: when a 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. How does JSP work? Answer: When JSP is accessed, it is first loaded by the server (Tomcat) and translated from the server into the corresponding ServletProgram, Compile and execute

15. What is the difference between JSP and Servlet? Answer: JSP is translated into servlet for execution, servlet is a Java program, it is easier to write Java code, JSP supports HTML syntax, so it is mainly used to produce dynamic web pages.

16. What are nine built-in JSP objects? Answer: Page request session application response pagecontext out config exception

17. Four data ranges in JSP: Answer: Page request session Application

18. Difference Between out and response. getwriter answer: Out is output to the browser based on response. getwriter. However, out and response. getwriter have different cache areas. when outputting content to the browser, the content of response. getwriter is output first, and then the content of out is output.

19. How to set the error-friendly page of the web project answer: Error Page: 1. configure it through errorpage iserrorpage in JSP 2. xml configuration <error-page> setting error page JSP internal error page can only solve the 500 error, Web. XML also solves the 404 error

20. Differences between include commands and JSP: include: Answer: include commands static introduction, introduced in the JSP source code phase, and then completed the translation process together JSP: include dynamic introduction. When the program is running, introduce the target resource and introduce the running result of the target resource.

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.