Summary of common error-prone problems in javaweb

Source: Internet
Author: User
Tags directory create session id set time tomcat server

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

2. How do I configure the Tomcat manager access user? Answer:conf/tomcat-users.xml main application debugging management, on-line system in the function must be closed off

3, release the project to Tomcat three ways Answer: Virtual directory configuration 1) Copy the site Directory to Tomcat/webapps (the site directory into the war Package ZIP format compressed package) 2) configuration Conf/server.xml <Host> in the configuration & Lt Context path= "" docbase= ""/> 3) Standalone profile conf new Catalina directory under the Catalina directory create a new host directory in the directory under Directories creating XML (the file name is the virtual directory path)

4. What are the steps to configure a virtual host in Tomcat? answer:1) in Conf/server.xml configuration

5, Tomcat Boot port is occupied how to handle Answer: * Tomcat server requires multiple ports 1) to see which port is accounted for 8005 2) FPort see which Port is occupied (DOS command) Netstat/ano tasklist 3) Shutdown by Task Manager (Windows service httpd)-----Task Manager failed to shut down service, stop service through service management

6. Servlet life cycle Answer:init (servletconfig) service (Servletrequest,servletresponse) destroy these three methods when performing init default first access, Load servlet call (config <load-on-startup> modify with server boot load) service every HTTP request, call----Multithreading call mode Destroy server stops when called

7. Write servlet step Answer:1) class extends HttpServlet 2) overwrite doget and dopost (if code logic, call each other) 3) Configure Web. XML <servlet> <serv Let-mapping>

8, service and doget, dopost relationship answer:service servlet life cycle definition, and implementation class HttpServlet definition Doget and dopost HttpServlet covered the service method, Invoke the corresponding doget and dopost according to the page request method

9, why it is recommended to overwrite the parameterless Init method without overwriting the init (ServletConfig) method Answer: There are parameters init to servletconfig some operations, in the parameter Init method called parameterless Init, in order to simplify programming, Direct override without parameter Init

10. What is the difference between ServletConfig and ServletContext Answer:servletconfig provides some initialization parameter information for each servlet, ServletContext each web app to create only one instance, It can be done to share data across multiple Web resources, provide initialization information for the entire Web application, and provide a request distribution method

11. What is the difference between forwarding and redirection Answer: in javaweb development, forwarding and redirection are resource access methods, forwarding is carried out within the server, only one request and one response, the client path does not change, forwarding can only access the internal resources of the site. Redirection is based on two requests and two responses, the server notifies the client to redirect to a resource, the client path changes, and redirects can be directed to the external resources of the site Request.getRequestDispatcher.forward Response.sendredirect Development application: Can be redirected to the place (redirected within the site) can use forwarding, when you need to pass data through the request (Request.setattribute), must use the forwarding

12, the common status Code 200, 302, 304, 404, 500 what meaning answer:200 Normal 302 redirect 304 cache 404 failed to find 500 server error

13, how to prevent the page hotlinking Answer: Through Request.getheader ("Referer")

14, how to set the expiration time of the webpage Answer:response.setDateHeader ("Expires", millisecond value); Expiration millisecond Value: Current time + How long does the time expire

15. What is the difference between setcharacterencoding and setContentType in response answer:setcharacterencoding setting the character encoding in the response, but does not notify the client setContentType is used to set the data file type to be sent to client, specifying 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 considerations? Answer: The text file is the type supported by the browser, Response.setheader ("Content-disposition", "attachment;filename=xxx"); If the file name is called Chinese, you need to encode the Chinese filename urlencoder when filename=xxx stitching it.

17. Why do I need to verify the code technology when I sign up for website? Answer: Prevent some malicious xxx

18, how to solve the user submit request data garbled problem Answer:post---request.setcharacterencoding get----manual transcoding url/new String, modify the Tomcat default decoding set Uriencodin G=xxx

19, Http://url?name=zhangsan+lisi----------use Request.getparameter ("name") to obtain the results Answer:zhangsan Lisi

20, iscommitted what meaning, when it is true, you can do the following method forward, redirect, include answer:iscommited to determine whether the response output has reached the client, if True Cannot perform forward redirect; include operation is possible

1, why to use cookies and session technology Answer:http protocol itself is stateless, the server to manage client status, cookies and session two management customer status technology

2, the principle of cookie technology? ANSWER:1) Client Access Server resource 2) the server specifies that the cookie is written to the client (response)----contains the cookie header information in the HTTP response 3) after the client receives the cookie information from the server, the cookie is saved by default in the browser memory (by setting a cookie MaxAge browser to save the cookie to your hard disk) 4) The next time the client accesses the server, it automatically carries cookie information

3. The life cycle of cookies? Answer: The default cookie is a session cookie when the session ends (browser off) cookie clears if the cookie is set maxAge the cookie expiration time is calculated based on the set time, and when the cookie expires, the browser clears the cookie

4. Session cookie and Persistent cookie difference Answer: Session cookie in memory, persistent cookie in hard disk

5. What are first-party cookies and third-party cookies Answer: First Party Cookies: access A to generate a cookie third party cookie: Access a generate B cookie

6, Session and cookie difference Answer:cookie information to save the client, session information to the server side, session technology based on cookie implementation, Write session Unique identifier SessionID to client in cookie form

7, session of the life cycle (session what time to create, what time to destroy) Answer: Create session:request.getSession destroy Session:1) server shutdown 2) session expires (server-side expiration) 3) s Ession.invalidate session Expiration Time two settings: 1) session.setmaxinactiveinterval (seconds) 2) Configure Web. XML <session-config> Unit minutes

8, the realization principle of Session Answer: Create a separate session object for each conversation, each object has a unique session ID, session ID is written back to the client in cookie form, so that the complete session object tracking

9, close the browser is destroyed the session Answer: not by default if the cookie is not persisted, the browser is turned off to destroy the client in-memory cookie (session ID), the server session still exists!

10, disable cookie,session can not use it? Answer:url rewrite

11, Session.removeattribute and Session.invalidate differences answer:removeattribute remove a data from the current session, invalidate destroy the current session object To remove all of the data

12, prevent form anti-refresh principle (token mechanism) Answer: When a client form is generated, a unique indicator (token) is generated, while the village token is inside the session and form hidden elements, when the form is submitted, the order number of the form is removed and the order of the session is compared, and the form submission is valid. Once the grade is used in the session, it will be cleared.

13, the principle of one-time verification code Answer: When generating a verification code, while saving the verification code to the session, the user submitted a verification code, and the session compared

14, the operation Principle of JSP? When the answer:jsp is accessed, the server (Tomcat) is first loaded, translated by the server into the appropriate servlet program, compiled and executed

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

16. What are the nine built-in objects of JSP? Answer:page Request Session Application response PageContext out config exception

17, four kinds of data range in JSP answer:page request session Application

18, out and Response.getwriter difference answer:out to the browser output, based on Response.getwriter completed. But out and response.getwriter have separate buffers, output content to the browser, first output response.getwriter content, and then output the out content

19. How to set up the Web project error friendly page Answer: error page: 1, within the JSP through ErrorPage iserrorpage configuration 2, the XML configuration <error-page> Settings error page JSP internal error page only resolves 500 error, Web. xml also resolves 404 error

20, include directive and jsp:include difference answer:include instruction Static introduction, introduced in the JSP source stage, introduced together to complete the translation process Jsp:include dynamic Introduction, when the program runs, introduces the target resource, introduces the target resource operation result

Summary of common error-prone problems in javaweb

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.