60 REAL TIME JSP Interview Questions and Answers

List of top 50 jsp interview questions and answers for freshers beginners and experienced pdf free download.

JSP interview Questions and Answers :-

1. Explain JSP and tell its uses.

2. What is the requirement of a tag library?

3. Explain JSP Technology.

JSP Interview Questions and Answers

JSP Interview Questions and Answers

4. Explain Implicit objects in JSP.

5. How can multiple submits  due to refresh button clicks be prevented?

6. Is JSP technology extensible?

7. Differentiate between response.sendRedirect(url) and <jsp:forward page = …> .

8. Can a subsequent request be accessed with one’s servlet code, if a request attribute is already sent in his JSP?

9. How to include static files in a JSP page?

10. Why is it that JComponent have add() and remove() methods but Component doesn’t?

11. How can a thread safe JSP page be implemented?

12. How can the output of JSP or servlet page be prevented from being cached by the browser?

13. How to restrict page errors display in a JSP page?

14. What are JSP Actions?

15. Differentiate between <jsp:include page=…> and <%@include file=…>.

16. Can constructor be used instead of init(), to initialize servlet?

17. Explain lifecycle methods.

18. Explain JSP Output comments?

19. Define Expression

20. Define Composition.

21. Define JSP Scriptlet.

22. How can information from one JSP be passed to another JSP?

23. Explain the uses of <jsp:usebean> tag.

24. Explain handling of runtime exceptions.

25.Why does _jspService() start with an ‘_’ but other lifecycle methods do not?

26. Explain the various scope values for <jsp:useBean> tag.

27. Show the 2 types of comments in JSP.

28.Can Static method be Override?

29. Explain JSP directives.

30. Explain pge Directives.


31. Show attributes of page directives.


32. What is Include directive?

33. What are standard actions in JSP?


34. Explain the jsp:setProperty action.

35. Define Static Block.

36. Explain jsp:plugin action.

37. Explain client and server side validation.

38. What is Translation Phase?

39. Perform a Browser Redirection from a JSP Page.

40.Give uses of Object Cloning.

41. How to forward a request to another source.

42. How can Automatic creation of session be prevented in a JSP page?

43. How can you avoid scriptlet code in JSP?

44. Explain the jspDestroy() method.

45. Explain the <jsp:param> action.

46. Explain static method.

47. How to disable scripting?

48.Define JSP Declaration.

49. How can HTML Output be prevented from being cached?

50. How is JSP better than Servlet technology?

51. Why don’t we need to configure JSP standard tags in web.xml?

We don’t need to configure JSP standard tags in web.xml because the TLD files are inside the META-INF directory of the JSTL jar files. When container loads the web application and find TLD files inside the META-INF directory of JAR file, it automatically configures them to be used directly in the application JSP pages. All we need to do it to include it in the JSP page using taglib directive.

52. How can we handle exceptions thrown by JSP service method?

To handle exceptions thrown by the JSP page, all we need is an error page and define the error page in JSP using page directive.

To create a JSP error page, we need to set page directive attribute isErrorPage value to true, then we can access exception implicit object in the JSP and use it to send customized error message to the client.

We need to define exception and error handler JSP pages in the deployment descriptor like below.

<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>

<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error.jsp</location>
</error-page>

53. How do we catch exception and process it using JSTL?

We can use JSTL Core tags c:catch and c:if to catch exception inside the JSP service method and process it. c:catch tag catches the exception and wraps it into the exception variable and we can use c:if condition tag to process it. Below code snippet provide sample usage.

<c:catch var =”exception”>
<% int x = 5/0;%>
</c:catch>

<c:if test = “${exception ne null}”>
<p>Exception is : ${exception}

Exception Message: ${exception.message}</p>
</c:if>
Notice the use of JSP EL in the c:if condition.

54. How do we print “<br> creates a new line in HTML” in JSP?

We can use c:out escapeXml attribute to escape the HTML elements so that it get’s shown as text in the browser, for this scenario we will write code like below.

<c:out value=”<br> creates a new line in HTML” escapeXml=”true”></c:out>

55. What is jsp-config in deployment descriptor?

jsp-config element is used to configure different parameters for JSP pages. Some of it’s usage are:

Configuring tag libraries for the web application like below.
<jsp-config>
<taglib>
<taglib-uri>http://journaldev.com/jsp/tlds/mytags</taglib-uri>
<taglib-location>/WEB-INF/numberformatter.tld</taglib-location>
</taglib>
</jsp-config>
We can control scripting elements in JSP pages.
We can control JSP Expression Language (EL) evaluation in JSP pages.
We can define the page encoding for URL pattern.
To define the buffer size to be used in JSP page out object.
To denote that the group of resources that match the URL pattern are JSP documents, and thus must be interpreted as XML documents.

56. How to ignore the EL expression evaluation in a JSP?

We can ignore EL evaluation in JSP page by two ways.

Using page directive as <%@ page isELIgnored=”true” %>
Configuring in web.xml – better approach when you want to disable EL evaluation for many JSP pages.
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<el-ignored>true</el-ignored>
</jsp-property-group>
</jsp-config>

57. When will Container initialize multiple JSP/Servlet Objects?

If we have multiple servlet and servlet-mapping elements in deployment descriptor for a single servlet or JSP page, then container will initialize an object for each of the element and all of these instances will have their own ServletConfig object and init params.

For example, if we configure a single JSP page in web.xml like below.

<servlet>
<servlet-name>Test</servlet-name>
<jsp-file>/WEB-INF/test.jsp</jsp-file>
<init-param>
<param-name>test</param-name>
<param-value>Test Value</param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/Test.do</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>Test1</servlet-name>
<jsp-file>/WEB-INF/test.jsp</jsp-file>
</servlet>

<servlet-mapping>
<servlet-name>Test1</servlet-name>
<url-pattern>/Test1.do</url-pattern>
</servlet-mapping>
Then if we can access same JSP page with both the URI pattern and both will have their own init params values.

58. Can we use JavaScript with JSP Pages?

Yes why not, I have seen some developers getting confused with this. Even though JSP is a server side technology, it’s used to generate client side response and we can add javascript or CSS code like any other HTML page.

59. How can we prevent implicit session creation in JSP?

By default JSP page creates a session but sometimes we don’t need session in JSP page. We can use JSP page directive session attribute to indicate compiler to not create session by default. It’s default value is true and session is created. To disable the session creation, we can use it like below.

<%@ page session =”false” %>

60. What is difference between JspWriter and Servlet PrintWriter?

PrintWriter is the actual object responsible for writing the content in response. JspWriter uses the PrintWriter object behind the scene and provide buffer support. When the buffer is full or flushed, JspWriter uses the PrintWriter object to write the content into response.

JSP Interview Questions and Answers pdf free download ::

Add Comment

Required fields are marked *. Your email address will not be published.