JSP interview questions
It is important both for interviewers and interviewees to prepare and get prepared for JSP Interview Questions, but first let's see what JSP is. JSP means JavaServer Page, is a technology developed by Sun Microsystems and allow us to create dynamic websites using Java programming language and based on HTML, XML or other document types. To deploy JSP servers, you can use Apache Tomcat or Jetty, similar to Apache PHP servers. Here you will find a compilation of useful JSP interview questions, so completely useful both for interviewers as interviewees, take a look at them and get ready.
JSP interview questions and answers
What's a servlet?
Servlets are very similar to the JAVA classes, are small programs or small code portions that are executed to create dynamic web pages, they receive parameters and give results.
What parameters do you use to initialize variables on JSP?
On JSP to initialize variables we use: <%! %>
What parameters do you use to indicate JSP code is going to be written?
Explain how comments can be used into JSP
Comments are very useful, you can put a invisible note that indicates what that portion of code does, or basically anything you want, on JSP comments can be initialized this way: <%-- <% portion of code%> --%>, so the "portion of code" is now invisible. Take into account that you can use HTML comments within the JSP code, but they become visible to the user:
<!-This portion will become visible to the user -->
And you should also know that you can use the JAVA comments within the JSP code:
// comment 1
/** comment 2 **/
Can you prevent your servlets from being cached by the browser? If answer is yes, How?
First of all, the answer is yes, How? Property setting the HTTP header attributes, just execute the following code at the beginning of your JSP pages.
response.setHeader("Cache-Control","no-store"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
Explain Include Action and Include Directive in JSP
Pocessed at the run time
Process the dynamic resourse
We can pass other parameter
Syntax: <%@ include file="fileName" %>
Processed at translation time
Include contents of resource but do not process the dynamic resource
We can't pass other parameter
What are implicit objects?
Basically are automatically instantiated objects, so are available by default on a JSP page, they are: request, response, page, config, out, session, pageContext, application and exception.
Explain the difference between sendRedirect and Forward
On forward requests, the user is not informed that a different resource will process the request, on sendRedirect, it indicates that a new URL should be requested, so obviously is slower than Forward.
Name the different types of scripting elements in JSP
Declaration elements, expression elements, scriptlet elements, action elements, directive elements.
Is JSP variable declaration thread safe?
No, if you declare a variable this way: <%int a = 0%> it will be only evaluated once, when the page is loaded, but if you declare it this way: <%int a = 0%> they are thread safe.
What advantages does JSP have?
There are many advantages JSP has, among the most common there are:
- Auto compilation.
- It works in various operating systems.
- JSP can be easy embedded into dynamic pages.
What is the difference between applets and servlets?
Applets are client side java programs executed by the browser and downloaded from the internet, servlets are server side programs which run on the server, also you can notice that applets do have GUI, while servlets don't, other difference is that applets are heavier to handle than servlets.
It is also important to have exercises among the JSP interview questions, they can vary according your requirements, you can pick them from the internet, you can create them, the important thing is to measure the creativity of the applicant, he/she must prove that has both theoretical and practical knowledge, and of course, a good abstraction level. JSP provides the same power than JAVA programming language, so the options available for web development is enormous, there is also a lot of printed and online material to check out, so in the way to prepare for a JSP interview, take a while to review all the material you can, that way you can do more elaborated interviews and also be more prepared, update constantly your knowledge and do not be afraid to test the new technology.