JSP and Servlets

JSP (JavaServer Pages) are Java programs encoded within webpages that research and generate pertinent results. Servlets, on the other hand, are objects (programs) that handle requests from users and provide results based on these requests.

859 Questions
JSP and Servlets
The Difference Between

What is the difference between JSP and Servlets?

A JSP is typically oriented more towards displaying information, and a servlet is more oriented towards processing information. For example, a JSP might display a report, while a servlet would process a user submitted form. These uses are not exclusive, but they are optimized more for performing tasks in this manner. It is much easier to incorporate HTML coding into a JSP than a Servlet. It is also easier to write more complex Java code in a servlet.

AnswerJSP has Implicit objects and Servlets do not. AnswerJSP and Servlet both define the server end functionality to provide dynamic outputs ,As we know our HTML is only the client end technology version which runs on client browser. JSP and Servlet differ each other in terms of represntation and execution cycle. Servlet are full functional java codes that define the output like write to stream files in protocol defined ways, JSP on the other hand is Role Sepated format to do so where a ordinary web designer designes how will be the presentation of the data and Programmer defines the functinality to provide the underlying things represented in conditional and non conditinal ways , But here is the magic of JSp that merges the both HTML represntation mixed with JAVA scriptlets.

Look at, it explains how does JSP differs from servlet.

Software and Applications (non-game)
JSP and Servlets

Whether Jsp is a front end or not?

JSP stands for the java server pages and it can be used independently or as the view component of a server-side model.JSP allows Java code and certain pre-defined actions to be interleaved with static web markup page.

JSP and Servlets

How do you retrieve data from an SQL database so that it can be viewed on a web page using JSP?

import java.sql.*;

public class Lookup { public static voidmain(String[] args) { String dbUrl = "jdbc:odbc:people"; String user = ""; String password = ""; try { // Load the driver (registers itself) Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection c = DriverManager.getConnection( dbUrl, user, password); Statement s = c.createStatement(); // SQL code: ResultSet r = s.executeQuery( "SELECT FIRST, LAST, EMAIL " + "FROM people.csv people " + "WHERE " + "(LAST='" + args[0] + "') "+ " AND (EMAIL Is Not Null) " + "ORDER BY FIRST"); while( { // Capitalization doesn't matter: System.out.println(r.getString("Last") + ", " + r.getString("fIRST") + ": " + r.getString("EMAIL") ); } s.close(); // Also closes ResultSet } catch(Exception e) { e.printStackTrace(); } } } ///:~

Java Programming
JSP and Servlets

Why servlet is faster than jsp?

The speed difference is not usually significant, but the slight performance advantage goes to Servlets because, JSPs get converted to Servlets before execution and since Servlets do not have this conversion phase, they are a little and I mean only slightly little faster than JSPs

JSP and Servlets

What is wcs and jsp?

JSP is a computer programming language like ASP but Linux

as far as i know WCS is Web Coverage Service

Java Programming
.NET Programming
JSP and Servlets
The Difference Between

What is the difference between .Net and Java?

Differences between .Net and Java include

  • Java is from Sun, .Net is from Microsoft
  • Java is a language plus a runtime, .Net is a runtime framework that supports multiple languages, Visual Basic and C# (the .Net language most similar to Java) among them.
  • C# is very similar to Java but a few years younger, and a bit nicer in some respects - it has a slightly simpler syntax for some common constructs.
  • Java is more platform independent, it runs on several operating systems including Windows, Mac and Linux. .Net is primarily for Windows. Although the open source project Mono is developing a multi-platform runtime for .Net, so this is less of an issue than it used to be.
  • .Net has a more integrated development environment, as the IDE, runtime and server all come from Microsoft as a standard package, while Java is based on third-party tool and server providers. It used to be the case that the .Net development environment was clearly superior, but the difference is smaller these days.
  • It can be argued that Java gives more flexibility, as there are more server- and IDE-providers to choose from, at the cost of some extra overhead for the developer to get the different pieces to work together.

Functionality wise, there is not a lot of difference between the two, at least not when used to develop web applications.

For desktop applications, .Net naturally has an edge in Windows integration.

note: Oracle bought Sun Microsystems (Sun).

Windows 7
JSP and Servlets

What does The server encountered an internal error that prevented it from fulfilling this request. exception org.apache.jasper.JasperException at org.apache.jasper.servlet.JspServletWrapper mean?

This essentially means that there was an error with the code of the page and that the server could not accomplish, or fulfill it's request. You'll have to try again later.

JSP and Servlets

How you convert int to string in jsp?

The same way you would in a regular java program.

int i = 10;

String s = i + "";

after the above line of code the variable s will have "10" as a string value...

JSP and Servlets
The Difference Between

What is the difference between an applet and a servlet?

Applet is a part of Core JAVA and Servlet of Advance Java. Applet is client side program and Servlet is Server side. When Applet runs it take the resources of client whereas Servlet is processed at server. An Applet's class, jar files can be accessed and downloadable by client but not so in case of servlet. Applets can run under any web browser their execution is dependent on Client as they require JRE Whereas Servlets do not require any thing specific at client side, as they require java enabled web/application Server. Dilpreet Singh (SCJP,OCA 9i)
The main difference is that a servlet is a server side component while applet is a client side component, moreover, a servlet doesn't have GUI while applet have GUI. A servlet runs inside a server and results are sent to client, so it consumes less network bandwidth, and also secure, while applet runs on client side in a browser, so entire code for applet is 1st sent to client and then it is executed on the client machine itself, so it also consumes more network bandwidth.

JSP and Servlets

Is it possible to synchronize a service method in Servlet?

Yes, by implementing SingleThreadModel interface

JSP and Servlets

How do you create a webpage using apache tomcat?

Apache`s Tomcat is an integrated web server. It si used for hoisting web sites with support for servlets, jsps and other server-side technologies. It IS NOT USED for CREATING websites. Make a web-page using html(you may use tools like dreamweaver or outlook for the design). Have a jsp script supporting the server side computations and run on apache webserver and feel the magic..

JSP and Servlets

What is servlet API in java?

Overview of the Servlet API

The Servlet 2.3 API consists of two packages: javax.servlet and javax.servlet.http. The base functionality is defined in the javax.servlet package whose classes and interfaces outline a generic, protocol-independent implementation. This means you can use it for non-Web applications, too. Of course, the exam targets the Web, so the HTTP protocol is the only one discussed in this blog. The javax.servlet.http interface defines classes and interfaces that are specific to the Hypertext Transfer Protocol (HTTP).

The javax.servlet Package

The javax.servlet package defines 12 interfaces, 7 classes, and 2 exceptions. These interfaces, classes, and exceptions are as follows.


• Filter:- Preprocessor of the request before it reaches a servlet. It can also be a postprocessor of the response leaving a servlet. It can modify a request or response (for example, change headers), the request to a resource (a servlet or static content), or the response from a resource.

• RequestDispatcher:- This is the servlet version of a redirect. It enables requests to be processed and then forwarded to other components of a Web application, such as another servlet, HTML file, or JSP file.

• Servlet:- Defines the life-cycle methods that are implemented by all servlets.

• ServletConfig:- This class has the methods for accessing the servlet configuration information such as the servlets name (from the web.xml file), the initialization parameters, and the ServletContext object.

• ServletContext:- These methods enable your servlet to communicate with its servlet container. This is how you get the MIME type of a file, dispatch requests, or write to a log file. Notice that this information has application scope. The most important features of the ServletContext are application-scope attributes access, logging, and context initialization parameters.

• ServletContextAttributeListener:- Implementations of this interface receive notifications of changes to the attribute list on the servlet context of a Web application. Supports the handling of the ServletContextAttributeEvent class.

• ServletContextListener:- An interface that supports the handling of the ServletContextEvent class. Defines a set of methods that a servlet uses to communicate with its servlet container. It can get the MIME type of a file, dispatch requests, or write to a log file. Notice that there is one context per "Web application" per Java Virtual Machine. The specification defines a "Web application" as a collection of servlets and content installed under a specific subset of the server's URL namespace, such as /catalog, and possibly installed via a .war file.

• ServletRequest:- This interface forms the base for the class that provides client request information to a servlet. It is protocol-independent.

• ServletResponse:- This interface forms the base for the class that represents the response sent from the servlet to the client.

• SingleThreadModel:- An interface that ensures a given servlet handles only one request at a time.


• GenericServlet:- An abstract class that implements ServletConfig. It defines a generic, protocol-independent servlet.

• ServletContextAttributeEvent:- This is the event class for notifications about changes to the attributes of the servlet context of a Web application.

• ServletContextEvent:- This is the event class for notifications about changes to the servlet context of a Web application (parent of ServletContextAttributeEvent).

• ServletInputStream:- Provides an input stream for reading binary data from a client request. You can modify it; it already has the readLine method for reading data one line at a time.

• ServletOutputStream:- An abstract class providing an output stream for sending binary data to the client. You print HTML, XML, or other output to the client using ServletOutputStream's print() and println() methods.

• ServletRequestWrapper:- Provides a convenient implementation of the ServletRequest interface that can be subclassed by developers wishing to adapt the request to a Servlet. This is where you can modify the behavior of request objects.

• ServletResponseWrapper:- Provides a convenient implementation of the ServletResponse interface that can be subclassed by developers wishing to adapt the response from a Servlet. This is where you can modify the behavior of response objects.


• ServletException:- Extends java.lang.Exception to provide a base class for defining servlet-related extensions.

• UnavailableException:- Extends ServletException to indicate that a servlet is temporarily or permanently unavailable.

The javax.servlet.http Package

The javax.servlet.http package defines eight interfaces and seven classes. These interfaces and classes are as follows:


The interfaces include the following:

• HttpServletRequest:- Extends javax.servlet.ServletRequest to support HTTP.

• HttpServletResponse:- Extends javax.servlet.ServletResponse to support HTTP.

• HttpSession:- Defines methods that provide access to persistent session-state information.

• HttpSessionActivationListener:- Implemented to handle the HttpSessionActivationEvent.

• HttpSessionAttributeListener:- Implemented to handle the HttpSessionAttributeEvent.

• HttpSessionBindingListener:- Implemented by objects that listen for HttpSessionBindingEvent events.

• HttpSessionListener:- Implemented to handle the HttpSessionEvent.


The classes include the following:

• Cookie:- Encapsulates HTTP cookies.

• HttpServlet:- An abstract class that extends javax.servlet.GenericServlet to provide support for HTTP.

• HttpServletRequestWrapper:- Provides the capability to wrap and modify incoming HttpServletRequest objects.

• HttpServletResponseWrapper:- Provides the capability to wrap and modify outgoing HttpServletResponse objects.

• HttpSessionBindingEvent:- Extends java.util.EventObject to define an event that is sent to an HttpSessionBindingListener when an object is bound or unbound from the current HttpSession.

• HttpSessionEvent:- Parent class of HttpSessionBindingEvent.

Learning Theories
JSP and Servlets

The Anatomy of a JSP page?

JSP Skeleton

Below is how a Skeleton JSP File would look like. (The file has to be saved as .jsp)

// Page Imports

<%@ page import = “ %>

// Tag Library References

<%@ taglib URI = “path to Taglib file” prefix = “xx” %>

// here xx refers to the prefix with which the tag library will be referred to

// HTML Head & Title Content

// Java Script Content

// HTML Body & Form Contents

Note: Java code can be placed within the <% %>tags in the body part of the JSP page within the Body tags

Plural Nouns
JSP and Servlets
The Difference Between

What is the difference of scfm and cfm?

SCFM is the amount (volume) of air that would happen if your air were at room temperature, and atmospheric pressure (0ft above sea level, 14.7psi). CFM (cubic feet per minute) is the amount (volume) of air that happens at the specific temperature and pressure. example: if you have a balloon that happens to be one cubic foot, and you are inside of a very hot, very high pressre room. when you walk out of the hot room, the flow rate is 1CFM, but because it is a balloon, when you take it outside the room it suddenly expands as it adjusts to outside (close to standard) conditions. So your balloon may be 3 or 4 SCFM. The two are interchangable, but when working in an industry that used flow rates heavily, it's much easier to note SCFM, because it has the added bonus of telling you temperature and pressure along with flow rate.

JSP and Servlets

How do you refresh a jsp page automatically?

by using the meta tag <meta HTTP-EQUIV="Refresh" CONTENT="5(duration in sec)">

JSP and Servlets

How do JSP methods get translated to Servlet methods?

A JSP gets converted into a Servlet for execution and hence the methods in a JSP are similar to the ones in a Servlet.

  • Scriptlets and Expressions will end up in the body of doGet or doPost
  • Declarations will end up as instance variables
  • jspInit() and jspDestroy() will get translated to Servlet's init() and destroy() methods
Computer Science
JSP and Servlets

How we can develop JSP pages using Custom Tags?

What is a Custom Tag?

The custom tag is a convention that allows you to have the container call the tag library life cycle event methods (for example, doStartTag), including the attribute get/set calls automatically invoked when attributes are declared in the custom tag. doStartTag and doEndTag methods are called when the JSP page request is processed.


< tagHandlerPrefix:customTagName / >

The above is a simple custom tag with no tag body.

Ways to use Custom Tags:

There are 4 ways of using Custom tags. They are:

1. < libraryPrefix : handlerName />

The custom tag with no body, said to be an empty custom tag.

2. < libraryPrefix : handlerName parameterName="value" >

This tag causes the container to call the setParameterName method and pass the "value" to it.

3. < libraryPrefix : handlerName parameterName="value" >

< % = 23 * counter % >

< b > Congratulations ! < / b >

< / libraryPrefix : handlerName >

A custom tag with a body. The body can contain core tags, scripting elements, HTML text, and tag-dependent body content between the start and end tags.

4. < library : outerTag >

< library : innerTag >

< / library : innerTag > < / library : outerTag >

This syntax is how you nest custom tags. The XML is easy, but the handler is more involved. Note that the following is wrong: .

JSP and Servlets

How do you run jsp page in eclipse?

As far as i know, you can't. Jsp pages is to be ran from server, preferably GlassFish.

JSP and Servlets

When should you use jsp and servlet in your project?

JSP and servlets are used in when you are building a website that provides a server sided service, for example connecting to a database is a service. == == JSP/Servlets are java code that perform the backend operations for web pages. Such servlets run in a java container, such as JBoss or Tomcat. Where you would use these would be in a web-based environment where you wanted to run the backend on Java, as opposed to PHP, Perl, etc. As an example, eBay is run by JSP/Servlet technology. However, JSP/Servlet technology is much more complicated than scripting languages, but well worth learning.

JSP and Servlets

What is the anatomy of a jsp page?

A JSP File Contents:

A JSP file can contain the following:

a. HTML contents

b. JavaScript

c. Java Code

Combining the features of the above 3 mentioned items; we get a powerful entity called the JSP. JSPs are used for the User Interface layer or the more colloquially called Front End layer of any J2EE application.

JSP Skeleton

Below is how a Skeleton JSP File would look like. (The file has to be saved as .jsp)

// Page Imports

<%@ page import = " %>

// Tag Library References

<%@ taglib URI = "path to Taglib file" prefix = "xx" %>

// here xx refers to the prefix with which the tag library will be referred to

// HTML Head & Title Content

// Java Script Content

// HTML Body & Form Contents

Note: Java code can be placed within the <% %> tags in the body part of the JSP page within the Body tags.

PHP Programming
JSP and Servlets

How are JSPs better than Servlets?

Though Servlets were awesome when compared to CGI, they still had some issues when it came to displaying dynamic content on a web page. Thankfully, Sun released the JSP (Java Server Pages) specifications in 1998, which solved all our UI woes. JSPs enabled programmers to display dynamic HTML content that could also use Java features.

Web Usability
JSP and Servlets

How will you pass values from HTML page to the servlet?

we are passing values from the HTML to the Servlet by using HTML controls.


In servlets we have one method for getting the values from HTML is getParameter()


String s1=req.getParameter("T1");

String s2=req.getParameter("T2");

in above example T1,T2 are the names of the HTML controls, String is a class and req is the object of the HttpServlet.

Ford Ranger XLT
Web Programming
JSP and Servlets

What is deployment descriptor in xml?

used for xml mappings

Computer Programming
JSP and Servlets

Create a table using JSP Servlets?

scope of operater

JSP and Servlets

Why jsp in j2ee?

JSP stands for Java Server Pages. JSP is an integral part of any j2ee application. It handles the User Interface (UI) layer of any web based application. It has support to execute java code and also can use HTML and java script. The output of a JSP page is usually viewed in a web browser like Internet Explorer or Mozilla Firefox etc.


Copyright © 2020 Multiply Media, LLC. All Rights Reserved. The material on this site can not be reproduced, distributed, transmitted, cached or otherwise used, except with prior written permission of Multiply.