JSP interview questions and answers for freshers:
1. What is JSP?
Ans. JSP stands for JavaServer Pages. It is a technology that allows developers to create dynamic, server-side web pages using Java.
2. What are the advantages of using JSP?
Ans. Some advantages of using JSP are: it allows for the separation of business logic from presentation logic, it is easy to integrate with Java code, it supports reusable components, and it is scalable.
3. How is a JSP page translated into a Servlet?
When a JSP page is requested, the JSP container translates it into a Java Servlet before it is executed. The JSP container generates the Java Servlet code that corresponds to the JSP page.
4. What is the difference between a Scriptlet, Expression, and Declaration in JSP?
Ans. A scriptlet is a block of Java code enclosed in <% and %>. An expression is a Java expression enclosed in <%= and %>. A declaration is a block of Java code enclosed in <%! and %>.
5. What is the use of JSP tags?
Ans. JSP tags are used to encapsulate reusable content or actions on a JSP page. There are two types of tags in JSP: standard tags and custom tags.
6. What is the purpose of the page directive in JSP?
Ans. The page directive is used to provide instructions to the JSP container. It can be used to specify the content type of the response, import Java classes, and specify session management settings.
- Top 10 Core Java Interview Question Answer
- 25 Java Interview Questions and Answer
- Spring Boot interview Questions with Answers [Top10 ]
- Java Program to remove duplicate elements in an Array (Best Program)
- Break Keywords in Java with Example
- Types of access specifiers in java
- Explain File Handling in Java with Program
7. What is JSP include directive?
Ans. The JSP include directive is used to include the content of another JSP page or HTML file at the current location in the JSP page.
8. What is the difference between JSP include directive and JSP include action?
Ans. The JSP include directive includes the content of another JSP page or HTML file at the current location in the JSP page during translation. The JSP include action includes the content of another JSP page or HTML file at runtime.
9. How can you use JSP tags to iterate over a collection?
Ans. You can use the <c:forEach> tag to iterate over a collection in JSP. The tag takes a collection as input and iterates over it, executing the body of the tag for each element in the collection.
10. What is the difference between a JSP page and a Servlet?
Ans. A JSP page is a text-based document that combines HTML or XML markup with Java code. A Servlet is a Java class that handles HTTP requests and generates HTTP responses. JSP pages are converted into Servlets before they are executed by the server.