JSP and Servlet face questions

Source: Internet
Author: User
Tags print object

Tag: request Apple to apply internal error to byte hid multithreading readability

1. Talk about the servlet execution process.
  Servlet的执行流程也就是servlet的生命周期,当服务器启动的时候生命周期开始,然后通过init()《启动顺序根据web.xml里的startup-on-load来确定加载顺序》
方法初始化servlet,再根据不同请求调用doGet或doPost方法,最后再通过destroy()方法进行销毁。
The difference between 2.Get and post
在页面提交数据时,get的数据大小有限制4k,post没有限制,get请求提交的数据会在地址栏显示,post不显示,所以post比get安全.
3. There are three servers, if the user logged on a server, the other two can no longer log on to this user, using session sharing, how do you do.
把所有的session的数据保存到Mysql服务器上,所有Web服务器都来这台Mysql服务器来获取Session数据。
4. Write a custom label to inherit what class
SimpleTagSupport,一般调用doTag方法或者实现SimpleTag接口
5.Jsp how to work with JSON
在 jsp 中处理 JSON,通常需要配套使用 JQuery 控件,并且导入一些 Common jar 包。使用 JQuery 控件是因为它能有效的解析并且展示 JSON 数据,
导入Common 则是因为 Java 中的对象并不是纯粹的数据,需要通过这些 Jar 包的处理使之转化成真实数据。
6. How to handle thread insecurity for Servlets
1.最简单的就是不使用字段变量,2.使用final修饰变量,3.线程安全就是多线程操作同一个对象不会有问题,线程同步一般来保护线程安全,
所以可以在Servlet的线程里面加上同步方法或同步块。(Synchronized)可以保证在同一时间只有一个线程访问,(使用同步块会导致性能变差,最好不去使用实例变量)
What is the difference between a 7.Jsp redirect and a forwarding process?
重定向是客户端行为,转发是服务器端行为重定向时服务器产生两次请求,转发产生一次请求,重定向时可以转发到项目以外的任何网址,转发只能在当前项目里转发重定向会导致request对象信息丢失。转发则不会转发的url不会变,request.getRequestDispatch().forward()重定向的url会改变,response.getRedirect().sendRedirect();

Detailed explanation look here

The difference between 8.JSP and servlet
Jsp的可读性强,容易看得懂,并且Jsp在最后会编译成Servletservlet容易调试,但是生成html页面工作量大
10.JSP can I operate the window?
Jsp不能够直接调用窗口,只能先生成打开窗口的js,再由js调用窗口
The difference between the main several methods of 11.Session
Session不能通过new创建,需要通过调用getSession()或者getSession(true)方法创建,getSession()是自动创建session,
getSession(true)是强制创建session,setAttribute()方法可以用于传值,getAttribute()可以用于取值(第一次创建session的时候,就是访问第一次一个jsp页面<这个页面的page指令 没有设置session=false>) 销毁session调用invalidate方法通过setMaxInactiveInterval()可以设定session的生存时间(web.xml可以设置session的生存时间)
12.Jsp of nine built-in objects, three instructions, seven actions of the specific function JSP nine large built-in objects:

PageContext: Valid only for the current JSP page, which encapsulates the basic request and Session object request: encapsulates the current requests session: Browser Sessions object, browser-wide active

Application: Application object, valid for the entire Web project out: Page print object, print string on JSP page Response: Returns server-side information to User config: A single servlet configuration object,

Equivalent to the ServletConfig Object page: The current Page object, which is this Exception: error page of the Exception object, if the specified error page, this is the exception object

Three major directives:

Page: Directives are directives for the current page include: used to specify how to include another page Taglib: for defining and specifying custom labels

Seven Big gestures:

Forward, perform a page jump, forward the processing of the request to another page Param: Used to pass parameters Include: used to dynamically introduce a JSP page Plugin: used to download JavaBean or applets to the client to perform Usebean:

Use JavaBean SetProperty: Modify the property value of the JavaBean instance GetProperty: Get the property value of the JavaBean instance

13. There are several ways to get the value of a page's elements, say it separately
request.getParameter() 返回客户端的请求参数的值request.getParameterNames() 返回所有可用属性名的枚举request.getParameterValues() 返回包含参数的所有值的数组
What are the differences between 14.Servlet and JavaScript, and what are their respective roles?
一个是服务端,一个是客户端Servlet是独立于平台和协议的服务器端的Java应用程序,可以动态生成Web页面,并采用响应--请求的模式提供Web服务JavaScript是一种解释性语言,用于向html页面提供交互行为,通常被直接嵌入在html页面中SErvlet is a Web application written in the Java language
Js是基于html上的一种解释语言
15.JSP Principle of execution
 客户端发出请求(request),Jsp引擎将jsp页面翻译成Servlet的java源文件,在Tomcat(Servlet容器)中将源文件编译成class文件,并加载到内存中执行,
把结果返回(response)给客户端。
Similarities and differences between 16.HTML and servlet

Different: HTML is static, the servlet is a Dynamic HTML page returned directly by the server, the servlet is used to process the client request, and returns an HTML page, the servlet needs the server to invoke the Servlet method to generate the Dynamic HTML page, And you need to configure the URL path in Web. xml

17. What is the difference between session tracking and what are their differences?

Cookie,session and application, a cookie is an HTTP object that can be manipulated by both the client and the server

The cookie is maintained in the client state, the session is maintained on the server side, because the cookie is stored locally on the client, so the data is easily stolen, when the traffic is very large,

Using the session will degrade the performance of the server, the scope of the application is the entire project only one, you can share data between different browsers, everyone can share,

So application is also unsafe, the difference between a cookie and a session

18. What are the hidden objects of JSP?
Request,out,response , pageContext , session , application , config , page , exception,也即jsp的九大内置对象
19.request, how response,session and application are used.
Request是客户端向服务端发送请求Response是服务端对客户端请求做出响应Session在servlet中不能直接使用,需要通过getSession()创建,如果没有设定它的生命周期,或者通过invildate()方法销毁,关闭浏览器session就会消失Application不能直接创建,存在于服务器的内存中,由服务器创建和销毁
20. Why not put objects in session
因为session底层是由cookie实现的,当客户端的cookie被禁用后,session也会失效,且应尽量少向session中保存信息,session的数据保存在服务器端,
当有大量session时,会降低服务器的性能
21. How to tell if the browser supports cookies
可以使用javaScript的方法navigator.cookieEnabled判断浏览器是否支持cookie
22.Request and session value differences, and garbled solution (cannot be set in Java code)
Request可以通过getAttribute()方法直接取值,也可通过getParameter()取值Session需要通过request.getSession().getAttribute()才能取值Request是针对一次请求,Session是针对整个会话      在页面通过contentType,pageEncoding,content设置编码格式,必须要一致
24.JSP page Jump
Jsp页面跳转有两种方式,forward和redirect(转发和重定向)
25. Say the JSP built-in objects and methods. Request: Client sends requests
getParameter() 得到前台传入的参数值
Response: Server-side return information to the user
PageContext: The properties of a Web page are managed here
Session: Conversation period related to the request
What the Application:servlet is doing
Out: The output used to transmit the response
Config:servlet's architectural components

Getinitparameter (String Paramnarne): Gets the value of the specified name from Web. XML getinitparameternames (): Get all the names from Web. xml

page:jsp page itself

Exception: Non-catching exception for error page GetMessage (): Return exception Details getclass (): Returns the name of the exception

26. There are several ways to upload the value of a page to the background
可通过get或post将值传递到后台,也可通过Jsp里面的setAttribute()方法将值传递到后台
27. How the value of a form form gets

The Request.getparameter () method can be used in the servlet to get the value of the form or request.getparametervaluse ();

How to get the form element of the child page in the parent page of 29.JSP, not how to take the value
通过设置属性setAttribute(),通过getAttribute()拿值,getParameter()方法可以做到
What does 31.404 and 500 mean?
404 :找不到url请求的路径,一般是工程名不对或者拼写错误500 :服务器内部错误,一般是服务器内部代码编写错误,也有可能是抛异常导致
32. Write 5 kinds of JSTL common tags
<c:if>,<c:item>,<c:foreach>,<c:out>,<c:set>
33.Jsp page The method of hiding an element
通过使用属性hidden可以将元素隐藏
35. We often encounter the output of some encoded characters, such as Iso-8859-1, in the development process of Web application, how to output a string of some kind of encoding
如将ISO-8859-1输出为GBK格式的字符, 通过new String(byte[] bytes,String charset) 构造器设置编码构造一个新的String(new String("ISO-8859-1","GBK"));
Those tags are in 36.Jsp.
jsp:include等
37. How to determine the user request is the first time, if the client and the server disconnect how to connect to the last operation
通过session中的isNew()可以判断是否是新用户,可以用cookie来保存信息到客户端,可以连接到上一次操作
38. If you create a servlet instance without constructing a method, how to create a servlet instance
Web容器会自动为servlet写一个无参的构造器,它使用class.forName("").newInstance()反射来创建servlet实例的
39.Servlet and filter Difference servlet: is used to process the request sent by the client, and then generate the response and pass it to the server server.
最后服务器将响应返回给客户端
Filter: is used to intercept a servlet container call servlet
可以在servlet进行响应处理前后做一些特殊的处理,譬如权限,日志,编码等
40. Explain the JSP <jsp:include page. The difference between > and <%@ include file%> dynamic import
  是行为元素、是在请求处理阶段引入的,引入执行页面或servlet所生成的应答文本先编译,后包含,就是将每个jsp页面都单独转化成html页面,最后再将所有的html页面相加,如果有相同变量不会冲突
<%@ include file= ""%> static Import
是指令元素是编译时包含,引入静态文本(html,jsp),在JSP页面被转化成servlet之前和它融和到一起。先包含,后编译就是将多个jsp一起解析,最后再一起生成html页面,如果有相同变量会冲突
What is the effect of PageContext?
可以使用pageContext对象来设定属性,并指定属性的作用范围,提供了对JSP页面内所有的对象及名字空间的访问
42.Servlet is a single case or multiple cases
是单例的,可以提高性能
43. How does the Interceptor (filter) perform
首先初始化过滤器,然后服务器组织过滤器链,所有的请求都必须需要先通过过滤器链,过滤器链是一个栈,遵循先进后出的原则 ,所有的请求需要经过一个一个的过滤器,
执行顺序要根据web.xml里配置的<filter-mapping>的位置前后执行,
每个过滤器之间通过chain.doFilter连接, 最后抵达真正请求的资源,执行完后再从过滤器链退出

JSP and Servlet face questions

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.