`

java中的servlet面试题

阅读更多
Q: Explain the life cycle methods of a Servlet.

A: The javax.servlet.Servlet interface defines the three methods known as life-cycle method.
public void init(ServletConfig config) throws ServletException
public void service( ServletRequest req, ServletResponse res) throws ServletException, IOException
public void destroy()
First the servlet is constructed, then initialized wih the init() method.
Any request from client are handled initially by the service() method before delegating to the doXxx() methods in the case of HttpServlet.

The servlet is removed from service, destroyed with the destroy() methid, then garbaged collected and finalized.
   TOP

Q: What is the difference between the getRequestDispatcher(String path) method of javax.servlet.ServletRequest interface and javax.servlet.ServletContext interface?

A: The getRequestDispatcher(String path) method of javax.servlet.ServletRequest interface accepts parameter the path to the resource to be included or forwarded to, which can be relative to the request of the calling servlet. If the path begins with a "/" it is interpreted as relative to the current context root.

The getRequestDispatcher(String path) method of javax.servlet.ServletContext interface cannot accepts relative paths. All path must sart with a "/" and are interpreted as relative to curent context root.
   TOP

Q: Explain the directory structure of a web application.

A: The directory structure of a web application consists of two parts.
A private directory called WEB-INF
A public resource directory which contains public resource folder.

WEB-INF folder consists of
1. web.xml
2. classes directory
3. lib directory
   TOP

Q: What are the common mechanisms used for session tracking?

A: Cookies
SSL sessions
URL- rewriting
   TOP

Q: Explain ServletContext.

A: ServletContext interface is a window for a servlet to view it's environment. A servlet can use this interface to get information such as initialization parameters for the web applicationor servlet container's version. Every web application has one and only one ServletContext and is accessible to all active resource of that application.
   TOP

Q: What is preinitialization of a servlet?

A: A container doesnot initialize the servlets ass soon as it starts up, it initializes a servlet when it receives a request for that servlet first time. This is called lazy loading. The servlet specification defines the <load-on-startup> element, which can be specified in the deployment descriptor to make the servlet container load and initialize the servlet as soon as it starts up. The process of loading a servlet before any request comes in is called preloading or preinitializing a servlet.
  [ Received from Amit Bhoir ]  TOP

Q: What is the difference between Difference between doGet() and doPost()?

A: A doGet() method is limited with 2k of data to be sent, and doPost() method doesn't have this limitation. A request string for doGet() looks like the following:
http://www.allapplabs.com/svt1?p1=v1&p2=v2&...&pN=vN
doPost() method call doesn't need a long text tail after a servlet name in a request. All parameters are stored in a request itself, not in a request string, and it's impossible to guess the data transmitted to a servlet only looking at a request string.
  [ Received from Amit Bhoir ]  TOP

Q: What is the difference between HttpServlet and GenericServlet?

A: A GenericServlet has a service() method aimed to handle requests. HttpServlet extends GenericServlet and adds support for doGet(), doPost(), doHead() methods (HTTP 1.0) plus doPut(), doOptions(), doDelete(), doTrace() methods (HTTP 1.1).
Both these classes are abstract.
  [ Received from Amit Bhoir ]  TOP

Q: What is the difference between ServletContext and ServletConfig?

A: ServletContext: Defines a set of methods that a servlet uses to communicate with its servlet container, for example, to get the MIME type of a file, dispatch requests, or write to a log file.The ServletContext object is contained within the ServletConfig object, which the Web server provides the servlet when the servlet is initialized

ServletConfig: The object created after a servlet is instantiated and its default constructor is read. It is created to pass initialization information to the servlet. 
  [ Received from Sivagopal Balivada ] 
分享到:
评论

相关推荐

    Java面试题,jsp&servlet面试题

    Java是企业级应用开发的...这些面试题涵盖了Java基础、集合框架、多线程、网络编程、Servlet和JSP等多个核心领域,全面展示了开发者应该具备的技能和知识。理解和掌握这些内容对于成为一名优秀的Java开发人员至关重要。

    jsp servlet面试题总结

    jsp servlet面试题总结 jsp 中九大内置对象为: 1. request 请求对象,类型 javax.servlet.ServletRequest,作用域 Request 2. response 响应对象,类型 javax.servlet.SrvletResponse,作用域 Page 3. ...

    最新Java面试题视频网盘,Java面试题84集、java面试专属及面试必问课程

    │ Java面试题04.java中int占几个字节.mp4 │ Java面试题05.java面向对象的特征.mp4 │ Java面试题06.装箱和拆箱.mp4 │ Java面试题07.==和equals的区别.mp4 │ Java面试题08.String.mp4 │ Java面试题09.讲一下java...

    JAVA项目经理面试题.pdf

    由于提供的【部分内容】信息量非常庞大且部分内容重复、混乱,难以从中准确提取出完整的知识点。但从这些内容片段中,...在实际的面试中,这些问题将帮助面试官评估候选人是否具备带领JAVA项目成功的必要知识和经验。

    常见的java,android面试题整理

    Java和Android面试题涵盖了许多核心概念,以下是这些知识点的详细说明: 1. **面向对象** (Object-Oriented Analysis and Design Principle, OOADP): 面向对象编程是Java和Android开发的基础,它涉及类、对象、继承...

    JSP和Servlet面试题

    常考面试题 1.讲下servlet的执行流程。 Servlet的执行流程也就是servlet的生命周期,当服务器启动的时候生命周期开始,然后通过init()《启动顺序根据web.xml里的startup-on-load来确定加载顺序》 方法初始化...

    servlet面试题

    在`destroy()`方法中,开发者可以编写代码来释放Servlet在`init()`方法中分配的资源,确保所有资源得到妥善处理。 ### GET与POST请求方式的区别 GET和POST是最常见的两种HTTP请求方法,它们在实际开发中有不同的...

    J2EE技术面试题 EJB面试题 JDBC面试题 JSP面试题 Servlet面试题

    5. **Servlet面试题**: - Servlet的生命周期,包括初始化、服务和销毁方法。 - Servlet的多线程问题,如何处理并发请求? - Servlet配置文件web.xml中,servlet和servlet-mapping元素的作用。 - 什么是Filter和...

    JAVA笔试面试资料JDBC HTTP、JSP、Servlet、Struts面试题汇总资料.zip

    Java重点面试题 – 针对java面试过程中经常遇到的一些试题进行总结.docx JAVA面试基础知识点总结.docx Java面试笔记.docx 写出正则表达式,从一个字符串中提取链接地址.docx 出现几率最高和覆盖范围最广的一套经典...

    知名企业java高级工程师面试题附答案

    ### Java高级工程师面试知识点解析 #### JSP与Servlet的异同及联系 - **相同点**:JSP和Servlet都属于Java Web开发的核心技术之一,主要用于动态网页的生成。 - **不同点**: - **本质区别**:JSP本质上是简化版...

    个人面试题总结(java,数据库,前端).zip

    文件中包含了本人最近在网上总结的面试题,有java面试题,jq面试题,jsp、servlet、ajax面试题,mysql面试题,oracle面试题,redis教案,也有最近时间总结的公司面试题,涉及的层面虽然不是很多,但是应对面试 应该...

    Servlet面试题 – Java Web开发面试题.doc

    这些面试题涵盖了Servlet的基础知识,包括HTML、JSP和JavaBean。理解并熟练掌握这些概念对于Java Web开发者来说非常重要,因为它们是构建动态网页和应用程序的基础。在面试中,能够正确解答这些问题将展示出你对Java...

    java面试大全视频版

    Java面试题19.Servlet中forward和redirect的区别 Java面试题20.jsp和Servlet的相同点和不同点 Java面试题21.内置对象和四大作用域和页面传值 Java面试题22.Session和Cookie的区别和使用场景 Java面试题23.mvc模式和...

    最全java面试题及答案(208道).pdf

    "Java面试题及答案详解" Java是目前最流行的编程语言之一,在软件开发行业中广泛应用。以下是Java面试题及答案的详解: Java基础 1. JDK 和 JRE 的区别是什么? JDK(Java Development Kit)是Java开发工具包,...

    JAVA编程百例+JAVA面试题集十套(经典)

    面试题(很多企业都常常从这些面试题库中选题作为笔试题): Java就业面试题大全.pdf Java最全的面试题.pdf java面试100题目.pdf SQL面试题大全.pdf 开发面试75条.pdf java 面试题 数据库方面.pdf 如何写出高性能的...

    JSP/Servlet Java面试逻辑题

    答:&lt;%@page isThreadSafe=false%&gt; 面试中会遇到! 6、页面间对象传递的方法 答:request,session,application,cookie等 7、JSP和Servlet有哪些相同点和不同点,他们之间的联系是什么? 答:JSP是Servlet...

    java程序员经典面试题

    Java 程序员经典面试题 本资源为Java程序员面试必备资料,涵盖了Java基础、线程编程、JSP、Servlet、JDBC、JDO、EJB、应用服务器、J2EE、MVC、设计模式等多个方面的知识点,旨在帮助Java程序员更好地准备面试,获得...

    java程序员面试题——863面试集

    - **Servlet 面试题**: 重点在于 Servlet 生命周期、请求处理机制等。 - **Struts 面试题**: 涉及 MVC 架构、配置文件解析、拦截器等。 - **Spring 面试题**: 包括依赖注入、AOP、事务管理等核心概念。 - **...

    java经典笔面试题

    Java是一种广泛应用的编程语言,Java面试题涵盖了Java基础知识、Java面向对象编程、Java集合框架、Java多线程编程、Java网络编程等多个方面。下面是对Java经典笔面试题的解读: 一、面向对象的特征 1. 抽象:抽象...

    Java面试笔记 225道Java面试题JAVA面试基础知识点总结Java数据结构题笔试WORD资料汇总(19个).zip

    Java基础、Java集合、多线程、JDBC、HTTP、JSP、Servlet、Struts面试题汇总(附答案).docx java工程师面试题大全-100%公司笔试题你都能碰到几个.docx Java开发工程师上机笔试题.docx Java开发求职面试题.docx Java...

Global site tag (gtag.js) - Google Analytics