answersLogoWhite

0


Best Answer

JSPs and Servlets can be used interchangeably for the most part. In fact, when a JSP is compiled, it is actually turned into a servlet! That being said, there are some guidelines for using servlets over JSPs or vice versa. Here are a couple of examples, but by no means a complete list: Typically, you would use a JSP to display dynamic data, or a form. A Servlet is usually what you would want to use to process a post or a get, especially considering the method that is called when you call a servlet (either doGet or doPost). For more information on this, here is a good article on Servlet and JSP Best Practices: http:/java.sun.com/developer/technicalArticles/javaserverpages/servlets_jsp

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: When do you use JSPs as opposed to Servlets?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Can you use jsp and servlets together?

Yes, JSP (JavaServer Pages) and Servlets can be used together in a web application. Servlets handle the business logic and processing of requests, while JSP is used to create the user interface and generate dynamic content. Servlets can interact with JSP pages to pass data and control the flow of the application.


How are jsps betten than servlets?

JSPs can contain HTML, JavaScript, XML and Java Code whereas Servlets can contain only Java Code, making JSPs more flexible and powerful than Servlets. However, Servlets have their own place in a J2EE application and cannot be ignored altogether. They have their strengths too which cannot be overseen.


Is it mandatory to learn servlets before JSP?

No. But, knowledge of Servlets would be an added advantage if you are learning JSPs


How can you learn Servlets and Jsps in an easy way?

Try the Head First JSP & Servlets book. It is a good book for learning them. You can also try the internet. You can get a lot of websites that give you tutorials on JSPs and Servlets. One of them is available in the related links section


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


What is used more in industry servlets or jsp?

Both are equally used and equally important. They are both used in conjunction. An application usually has 1 or 2 servlets but has numerous JSPs. So, if we go by pure number, JSPs are more.


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.


What is the difference between a Web Server and a Application Server?

== == The basic difference between a web server and an application server is Webserver can execute only web applications i,e servlets and JSPs and has only a single container known as Web container which is used to interpret/execute web applications Application server can execute Enterprise application, i,e (servlets, jsps, and EJBs) it is having two containers 1. Web Container(for interpreting/executing servlets and jsps) 2. EJB container(for executing EJBs). it can perform operations like load balancing , transaction demarcation etc etc


What is the need of servlet?

Servlets were the alternative to CGI and were released in 1997. Unlike CGI, which starts a process for each request, Servlets just spawn a new thread. Servlets had a better or rather efficient architecture which was able to handle the loads of the internet. 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. The combination of JSPs and Servlets was just what the Doctor Prescribed and it just revolutionized the Web Programming industry.


How can you debug jsp pages?

There is an IDE called WSAD - Websphere Studio Application Developer. It has inbuilt tools to debug everything (servlets & jsps inclusive) I have heard from my friends that Eclipse too has some plugins that can help us debug jsps. The MyEclipse plugin for Eclipse also has tools for debugging Servlets and JSPs. Debugging a JSP in MyEclipse is a little tricky sometimes, depending upon the Java Application Server you are using. In theory, it should not be too difficult to debug a JSP as when it is compiled, it is compiled into a Servlet anyway.


What is j2ee and how it is used in real time?

J2EE standa for Java 2 Enterprise Edition. It is used for creating enterprise web applications. J2EE is an advanced java technology that makes use of Servlets and JSPs to provide enterprise applications like web pages and portals.


Why jsp cannot be used as mvc controller instead of servlets?

Because JSPs are designed to take care of the View part of the MVC design patter and not the controller. You can have little or some amount of logic in it, but it is not designed/created with the idea of controlling the flow of control in a J2EE application.