Interview seven

Compare Java and JavaSciprt?

- ----- object-based and object-oriented:

Java is a true object-oriented language, even the development of simple procedures, must design objects; JavaScript is kind of scripting language that can be used to make the network independent, user interaction with complex software. It is an object (Object-Based) based and event-driven (Event-Driven) programming language, which itself provides a very rich internal object for designers to use.

- --- interpreted and compiled:

Java source code before execution, must be compiled.

JavaScript is an interpreted programming language, its source code need not compiled, interpreted by the browser execution. (Almost all browsers currently use the JIT (time compiler) technology to enhance the operating efficiency of JavaScript) - --- ------- strongly typed variables and the weak type variables:

Java using a strong type variable checking that all variables before compiling must make a statement;

JavaScript is weakly typed variable, silent even out before use variable, JavaScript interpreter at run time type checking data inferred. - --- code format is not the same.

Java how to jump out of the current multiple nested loops?

Before adding a tag outermost loop such as A, then break A; can jump out of multiple loops.

We often come across some kind of output encoded characters, such as iso8859-1 and other web application development process, you talk about how a certain output encoded string?

Public String translate (String str) { 
     String tempStr = “”; 
     try { tempStr = new String(str.getBytes(“ISO-8859-1″), “GBK”); 
     tempStr = tempStr.trim ();
     } catch (Exception e) { 
           System.err.println(e.getMessage()); 
        } 
return tempStr;
 }

Java Web What are common technical specifications (assembly) usually contain?

JSP and Servlet : JSP is actually the essence of Servlet, after all JSP pages need to be compiled into a Servlet, and then to process user requests, generate a response. Servlet typically needs to be configured, either using XML elements arranged in web.xml @WebServlet annotation configuration may also be used.

Filter: effect of the Filter is to filter user request or response, which may be pretreated user request, the response may be post-treatment. Filter chain using a typical process: Filter pretreatment user requests, then the request to the Servlet to process and generate a response, then the post-processing Filter server response. . Filter typically needs to be configured, either using XML elements arranged in web.xml @Filter annotation configuration may also be used.

Listener: Listener is the listener. Different the Listener listens for events, ServletContextListener monitor start and end Web applications; HttpSessionListener monitor the beginning and end user sessions; ServletRequestListener monitor user requests; there ServletContextAttributeListener, HttpSessionAttributeListener, ServletRequestAttributeListener properties were listening application, session, request the range of change . Listener needs to be configured, either using XML elements arranged in web.xml annotation configuration may also be used.

Tag Library: tag library is an excellent presentation layer technology. By tag library can be encapsulated in the complex data show simple logic Tags. Tag libraries usually need to write tag handler class, and then configure tags * .tld file. JSTL standard tag library is provided by the official Java Web.

EL expression language : EL expression language is not a real programming language, it is only a data access language, commonly used to access Java Web application data within each range.

Difference HTTP request GET and POST?

  1. Request sends the GET request the parameter names and values ​​converted to a string, the URL and appended to the original, it is possible to see the request parameter name and value in the address bar. POST request body submit a request using the request data, and therefore invisible to the user.

  2. GET requests a smaller amount of data transferred, generally not greater than 2KB. Amount of data transferred large POST method is generally considered the size of the POST request parameter is not limited, to limit depends only on the server.

  3. POST request more secure, do not use GET POST

What are common Web server? The application server What? What's the difference?

Common Web server has Tomcat, Jetty, Resin and so on.

Common application servers have WebLogic, WebSphere, JBoss, Glassfish and so on.

Web servers typically support only Java Web standards, such as can only support JSP, Servlet, Listener, Filter and other technologies typically can support JNDI, and other data sources. Therefore less Web server supports.

The application server will need to fully support Java EE specification, not only need to support all the features of Java Web, also need to support JTA, EJB, JMS, JPA and other Java EE specification, and therefore more powerful functionality of the application server. However, WebLogic, WebSphere prices are very expensive, most small and medium enterprises can not afford an expensive product, and is currently businesses are more popular use of lightweight Java EE development framework, which often use lightweight Java EE Spring, Hibernate , MyBatis and other open source frameworks, open source framework does not require the application server support, so now general business applications do not require the use of an application server.

Web applications deployed in Tomcat There are several?

Web application is very simple to deploy on Tomcat, actually deploy Web applications on all Web servers are simple.

Web applications deployed in Tomcat are usually several. ¾ the use of automatic deployment of Tomcat.

  • Use the console to deploy
  • Add custom Web deployment files.
  • Modify server.xml file to deploy Web applications.

If you deploy to the Tomcat Web application in the development phase is more simple, such as using Eclipse EE version, simply select the Web application, right-click menu of "Run on Server" to deploy the application to the specified Web server.

What is Servlet?

Servlet is a platform-independent Java classes, write a Servlet, in fact, it is in accordance with specifications write a Java Servlet class. Servlet is compiled into platform-neutral byte code that can be dynamically loaded into the Java technology-enabled Web server is running. Web Servlet is a Java-based component, running on the server, management by the Servlet container for generating the dynamic content.

Servlet life cycle.

Servlet have a good definition of survival, including loading and instantiation, initialization is complete, process the request and services. The survival of javax.servlet.Servlet interface init, service and destroy methods behalf.

After the Web server Servlet is instantiated, its init container runs, the method is run only once, to make some preparation work, the process ends when the Servlet can process client requests throughout the life cycle.

The method of operation of its service request arrives the client, a method of automatically sending a service request doXxx corresponding method for operating (doGet, doPost) and the like, which runs multiple times throughout the life cycle of every request service using a method for processing.

When the server decides to destroy the instance when calling its destroy method, which runs only once during the entire life cycle, for doing some cleanup work.

The difference between forward and redirect?

  1. Internal server jump forward (in the current jump in webapp), after the jump URL address bar is not displayed; sendRedirect is force the browser to re-issue the request, the address bar displays the URL after the jump.

  2. After performing forward is still the last request, after performing redirect would generate a second request. Therefore, forward target page can be accessed request parameters of the original request, as is still the same request, request parameters of all the original request, request a range of properties all present; redirect target page request parameters can not access the original request, because it is the second the second request, the request parameters of all the original request, request a range of property lost.

  3. When forward in front of what is requested, after the jump or what the request, and must get sendRedirect the request.

  4. If you want to request access to the other webapp. Because the internal server jump forward, only to jump in the current webapp, it is not complete, and therefore can only be used to redirect sendRedirect.

ServletConfig object and ServletContext objects What is the difference?

A Servlet ServletConfig object there is one, can be used to read the configuration parameters of the Servlet.

A Web App ServletContext object corresponds to one, and therefore representative of the entire Web application ServletContext, such as the need to read the configuration parameters of the entire Web application, to access the application range of properties, all ServletContext.

In fact, application built-in object is an instance of ServletContext.

To acquire resource file webapp or context.getRealPath ( "/"); ServletContext objects can context.getResourceAsStream ( "/ images / tomcat.gif").

ServletContext object setAttribute (String name, Object o) to transform the object stored in the Context scope scope domain is also called the global domain, can be shared among the entire web application.

ServletContext objects can communicate and servers, such as writing information to the log information among servers.

Servlet session mechanism?

Because the HTTP protocol is stateless protocol, also known as one-time connection, so the webapp must be a mechanism to remember a series of user operations, and uniquely identifies a user.

Cookie: is the use of a short text store user information, the page is finished loading saved by written response back to the client.

Session: save the data on the server, Session is a single customer of a block of memory to store data.

Tomcat's Session is to achieve a HashMap.

Session object is created when the server request.getSession (), and generates a unique SessionID. SessionID write will be saved back to the client by Cookie. Cookie is disabled if the client can only use the URL rewriting mechanism.

Session object can setAttribute (String name, Object o) in the scope of a Session object storage domain. Session scope is a domain in the browser to open the browser is closed.

What Filter is? what's the effect?

Filter is a filter, it may be pretreated both a user request, the response may be post-treatment. Struts 2 core controller is implemented using a Filter. Filter may be responsible for intercepting a plurality of requests or responses; a request or response may also be a plurality Filter intercepted.

Commonly used are as follows Filter:

  • Authorized users Filter: Filter responsible for checking user requests, filtering illegal user request upon request. ¾ log Filter: Detail Record some special user request.
  • Responsible for decoding Filter: comprising decoding an encoded non-standard request

What Listener that? what's the effect?

Listener Servlet refers to the listener.

Listener objects can ServletContext, HttpSession objects, ServletRequest listens object. ServletContext object can monitor, the HttpSession objects, the start and end ServletRequest objects, may change their properties correspond listening range.

Commonly used Listener has the following:

  • ServletContextListener: monitor start and end Web applications.
  • HttpSessionListener: Session monitor the start and end users.
  • ServletRequestListener: listening to user requests.
  • ServletContextAttributeListener: change the properties of listening application range.
  • HttpSessionAttributeListener: change the properties of the listening session range.
  • ServletRequestAttributeListener: change the properties of a range of listening request.

What's new in Servlet 3.0 have

Servlet 3.0 relative to the Servlet 2.0 is a big change is the introduction of notes instead of XML configuration for simplified Web application development and deployment. Several main features:

  1. The new annotation support: This version adds a number of annotations to simplify the Servlet, filter (Filter) and the listener (Listener) configuration, which makes the web.xml file from this version is no longer a mandatory .

  2. Asynchronous processing support: With this feature, Servlet thread no longer needs to block until the business can be re-processed output response, after the end of the Servlet thread. After receiving the request, Servlet thread may be time-consuming operation assigned to another thread to complete their return to the container without generating a response. For the case of the more time-consuming business processes, which will greatly reduce the footprint of server resources, and improve the concurrent processing speed.

  3. Pluggable support: Developers familiar with Struts 2 will remember and integrate various common characteristics, including Spring Framework, including its way through plug-ins. The respective plug and packaged into JAR files in the class path, Struts 2 runtime plug-ins can be automatically loaded. Servlet 3.0 now offers a similar feature, developers can easily expand the functionality of existing Web applications through plug-ins, without the need to modify existing applications.

  4. Improved file upload API, before the Web application to upload files typically need the help of tools such as common-fileupload, but Servlet HttpServletRequest 3.0 can handle direct file uploads, developers simply use @MultipartConfig modify the Servlet, we can now move the Servlet getPart HttpServletRequest method used to obtain file upload fields.

JSP is the What? What are the characteristics?

JSP stands for Java Server Pages, and it Servlet technology, are the Sun (already acquired by Oracle) defined for dynamic Web site development technology. JSP directly embedded Java script in an HTML page, the page can be displayed so that the dynamic data.

Compared Servlet HTML tags embedded in Java code, JSP has the advantage of a more convenient display on the page.

The nature of JSP or Servlet, JSP Web server will be compiled into Servlet, JSP therefore in fact or in the form of Servlet running. In the actual development, often using the MVC model development, which acts as a controller Servlet, Servlet responsible for processing requests, and call processing requests Service and other components, and acquire data through Service and other components, but just as JSP view, to show the work is responsible for data .

JSP page which contains the syntax? They have what characteristics?

JSP pages can contain the following four kinds of syntax:

  1. JSP comments: its syntax is: <% - comment -%>, the difference between JSP comments and HTML comments that: JSP comment is a comment server, Web server when compiling JSP page processing, it will ignore the JSP Notes, JSP compiler-generated JSP Servlet does not include comments, so JSP comments are not output to the browser. The HTML comments will be output to the browser.

  2. JSP statement: The syntax is: <!% Declaration%>. JSP statement Servlet corresponding to the variable part of the member, so the JSP declaration syntax defined fields, methods, internal class, and these fields, methods may also be used private, protected, public, static, etc. modified modifier. Since the content of the statement is a member of the JSP Servlet, so they can be used in all scripts.

  3. JSP script (also known as Java Script): The syntax is: <% statement%>. JSP Servlet script corresponding to the execution of the service method code, JSP script can define local variables and place executable statement of the local variables defined in the script JSP not use private, protected, public, static, etc. modifier modification, the only modifiers can be used is final.

  4. Expression (also known as output expression): The syntax is: <% = expression%>, this syntax is relatively simple, can only be used on a page output value of the expression. JSP expression corresponding to the JSP script corresponding to the Servlet's service method in a out.writeln (expression) statement.

JSP compiler directives What?

JSP using the compiler command syntax is:

<% @ Directive compiled name attribute name = "attribute value" ...%>

JSP compiler directive has the following three:

  1. page: This instruction is an instruction for the current page, commonly used to specify some settings information for the page, such as the character set of the page, the page needs to import Java packages. A JSP page can contain multiple page instructions.

  2. include: used to specify to include another page. This is called a static contains included. A JSP page can contain multiple include directives.

  3. taglib: introducing a custom tag library. A JSP page can contain multiple taglib directive.

Guess you like

Origin www.cnblogs.com/bzbz/p/11987019.html