Super practical Java web interview questions

Java web interview questions
you want to face more questions and learning materials can contact me whisper, share with everyone to learn!

1, Tomcat optimization experience
A: remove the monitoring of web.xml and the editor jsp advance into Servlet.
A surplus of physical memory, the increased use of tomcat jvm memory

2, the difference between GET and POST method of HTTP requests
Answer: servlet has a well-defined lifetime, including loading and instantiation, initialization is complete, process the request and services. The survival of javax.servlet.Servlet interface init, express service and destroy methods.
3, explain what servlet;
A: servlet has a well-defined lifetime, including loading and instantiation, initialization is complete, process the request and services. The survival of javax.servlet.Servlet interface init, express service and destroy methods.
? 4, talk about the Servlet life cycle
Answer: servlet has a well-defined lifetime, including loading and instantiation, initialization is complete, process the request and services. The survival of javax.servlet.Servlet interface init, express service and destroy methods.

After Servlet is instantiated server, container runs its init process runs its service method when a request arrives, the service method of automatically sending doXXX method of operation corresponding to the request (doGet, doPost), etc., when the server decides examples of the destruction when calling its destroy method.
web container loads the servlet, life cycle begins. Initializes the servlet by calling the servlet's init () method. Achieved by calling the service (), according to different call requests do *** () method. The end of the service, call the servlet's destroy web container () method.

5, Servlet basic structure
public class ServletName the extends the HttpServlet {
public void the doPost (the HttpServletRequest Request, the HttpServletResponse Response) throws
ServletException, IOException {
}
public void the doGet (the HttpServletRequest Request, the HttpServletResponse Response) throws
ServletException, IOException {
}
}
. 6, SERVLET the API in forward () and redirect () the difference?
Answer: the former is only the steering control of the container, the client browser's address bar does not show the address after the shift; the latter is complete Jump, the browser will be Jump address, and re send request link. In this way, you can see the link after the jump address from the address bar of your browser. Therefore, the former more efficient and meet the needs in the former, try to use forward () method, and, this also helps hide the actual link. In some cases, for example, you need to jump to an other resources on the server, you must use
sendRedirect () method.

7, call doGet () and doPost () Under what circumstances?
Jsp page FORM tag attributes of method calls doGet is get (), doPost call is post ().

8, the main method Request object:
the setAttribute (String name, Object): Set the name of values for the parameters request the name of
getAttribute (String name): Returns the specified by the name attribute value
getAttributeNames (): returns the names of all attributes request object set , the result is an enumerated example
getCookies (): returns the client all the Cookie objects, the result is a Cookie array
getCharacterEncoding (): returns the character encoding request
getContentLength (): returns the length of the request the Body
getHeader (String name) : get HTTP protocol definition file header information
getHeaders (String name): returns the name of all the values of the request header, the result is an enumeration of instances
getHeaderNames (): returns the name so request header, the result is an enumeration of instances
getInputStream (): returns the input stream request for obtaining data request
getMethod (): get the client transmits data to the server-side method
getParameter (String name): get the client to the server-side to define the value specified by name
getParameterNames (): get the client to transfer The names of all server-side parameters, the result is an instance of the enumeration
getParametervalues (String name): get all values are specified by name arguments
getProtocol (): get the client to transmit data to the server is based on the protocol name
getQueryString (): get the query string
getRequestURI (): Gets the requesting client address string
getRemoteAddr (): get the client's IP address
getRemoteHost () : get the name of the client
getSession ([Boolean create]): returns and requests related to the Session
getServerName (): get the name of the server
getServletPath (): Gets the path of the script file requested by the client's
getServerPort (): Gets the server port number
removeAttribute (String name): To delete an attribute request

9, forward and redirect the difference between
forward a request to the server resources, the server URL to directly access the target address, the response content that URL to read over, and then put these elements and then distributed to the browser, the browser does not know the content sent by the server where did it come from, so it's address bar or the original address.
redirect server is based on logic, send a status code that tells the browser to re-request the address, in general, the browser will just re-request with all the parameters of the request, so the session, request parameters can get.
10. What is the difference request.getAttribute () and request.getParameter ()?

  1. Which jsp built-in objects have? What role are? Is there any way were?
    Answer: JSP total of the following nine built-in objects:
    Request client requests, which will include parameters from GET / POST requests
    response page returns a response to the client's
    property pageContext page is here to manage
    session session period relating to the request for
    application the servlet is being executed
    out in response to the output used to transmit
    config servlet framework components
    page JSP page itself
    exception for an error page, uncaught exception

request represents the HttpServletRequest object. It contains information about the browser request, and provides a useful way to get a few cookie, header, and session data.
HttpServletResponse object represents a response, and provides a method (e.g., as cookies, header information, etc.) for setting the number back to the browser in response to the
out object is an instance of javax.jsp.JspWriter, and provides several ways to make you used to send output back to the browser.
pageContext represents a javax.servlet.jsp.PageContext object. It is used to facilitate access to a diverse range of name space, the API associated servlet object, and a method of packaging a general-purpose functions associated servlet.
represents javax.servlet.http.HttpSession session object requested. Session state information of the user can store
applicaton represents a javax.servle.ServletContext object. This helps to find information about the servlet engine and servlet environment
config represents a javax.servlet.ServletConfig object. This object is used to access the servlet instance initialization parameters.
It represents a page from the servlet instance generated page

  1. What action jsp What role are??
    (The problem seems unimportant, do not understand why there is this question)
    Answer: JSP total of the following six basic action
    jsp: include: the introduction of a file when the page is requested.
    jsp: useBean: Find or instantiate a JavaBean.
    jsp: setProperty: set the JavaBean properties.
    jsp: getProperty: output of a JavaBean properties.
    jsp: forward: the request to a new page.
    jsp: plugin: generated according to the type of browser Java plug OBJECT or EMBED tag
    13, JSP common instruction
    isErrorPage (whether to use the Exception object), isELIgnored (whether to ignore expression)

  2. JSP difference between static and dynamic INCLUDE INCLUDE is?
    A: Dynamic INCLUDE with jsp: include action to achieve
    <jsp: include page = included.jsp flush = true /> it always checks changes contained in the document, suitable for containing dynamic pages, and may be static parameters used INCLUDE include pseudo-code implementation does not check the changes contained in the given file for containing static page <% @ include file = included.htm% >

15 Both are ways to jump what is? What is the difference?
(Answer below a critical error, and should ask the difference between the sendRedirect forward, after all, a question of people not engaged in professional writing in the arts, communication skills may not see too strong, words are not necessarily accurate, together with its own technology may also face some problems, not necessarily to really articulate what he meant, strictly speaking meaning, some problems may simply no one can answer, therefore, to take the initiative when the answer is clear enough as long as they know the expression, without specifying what the original meaning of the title is going to weigh, do not blindly think is the answer)
a: there are two, namely:
<JSP: the include = = the flush to true included.jsp page>
<JSP: Forward page NextPage.jsp = />
the former page does not include within the meaning of the page turning, the page just display the results, or the main page of the original page. After the implementation will come back, the equivalent of function calls. And can take parameters. The latter completely turned a new page and never return. Equivalent to go to the statement.

16. The method of transfer objects between pages
request, session, application, cookie, etc.
17, JSP and Servlet What are the similarities and differences What is the connection between them is?
JSP is an extension of the Servlet technology, Servlet is a simple way of essence, more emphasis on the appearance of the application of the expression. After the JSP compiler is "class servlet". Servlet and JSP main difference that the application logic is a Java Servlet file, and completely separated from the HTML presentation layer. The situation JSP is Java and HTML can be combined into a .jsp file extension. JSP focuses on view, Servlet mainly for control logic.

18, various parts of the MVC have realized how those technologies to achieve??
Answer: MVC is the Model-View-Controller shorthand. Model represents the business logic of the application (by JavaBean, EJB component implementation), View application is a surface (generated by JSP pages), Controller provides process control application (typically a Servlet), such a design model the application logic, processing and display logic implemented into different components. These components can interact and reuse.

19, we often encounter some kind of output encoded characters, such as iso8859-1 and other web application development process, how a certain output encoded string?
Translate String public (String STR) {
String tempStr = "";
the try {
tempStr = new new String (str.getBytes ( "the ISO-8859-1"), "GBK");
tempStr tempStr.trim = ();
}
the catch ( E Exception) {
System.err.println (e.getMessage ());
}
return tempStr;
}
20 is. Now n digital inputs, comma separated; then select liter or descending order; another page is displayed on the submit button press according to what sort of results provide reset,

Guess you like

Origin blog.51cto.com/14623707/2459434