Forums Register Login

Difference between Servlet, JSP and Java

+Pie Number of slices to send: Send
Hello Guru's

I am little bit confuse about SERVLET, JSP and JAVA.
If I am using web design for SERVLET with TOMCAT.
Why I want to use JSP and JAVA.

Pls explain to me.

Thanks, Raghu.K
[ October 11, 2006: Message edited by: Bear Bibeault ]
+Pie Number of slices to send: Send
MVC - JSP is the View. Servlet is the Controller, and Model is usually just some form of a JavaBean. It's all Java.
+Pie Number of slices to send: Send
java is a programming language, Servlets and jsps are web technologies built for J2EE (framework|methodology|platform). Tomcat is a popular servlet container used for building web based applications.

For more information visit the sun website at http://java.sun.com
+Pie Number of slices to send: Send
 

If I am using web design for SERVLET with TOMCAT.
Why I want to use JSP and JAVA.



If you are "using web design for SERVLET with TOMCAT", then you are using the computer programming language called JAVA to write your SERVLET.

A SERVLET displays html in a browser window using the println() command, and it looks like this:

out.println("<html>\n"
+ "<head>\n"
+ "<title>My html page</title>\n"
+ "</head>\n"
+ ...
+ ...
+ "</html>"

As you can imagine, outputting a whole html page to a browser like that is a big hassle: you have to put quotes around all the html and you have to add a "\n" to output the html on a newline.

Instead a SERVLET can use a JSP page to display the html. A JSP page looks like a normal html page--except that it has a few lines of JAVA in it, for instance:

<html>
<head>
<title>My html page</title>
</head>
<body>
<% String firstname = request.getParameter("firstName"); %>
<div><%= firstname %></div>
</body>
</html>
[ October 11, 2006: Message edited by: sven studde ]
+Pie Number of slices to send: Send
except that it has a few lines of JAVA in it.

Don't let Bear hear you say that.
+Pie Number of slices to send: Send
Ragu,

A few points to help you get the most out of JavaRanch as a resource:

1) Please modify your display name to mixed case. The all-uppercase can be construed as "shouting" and may considered rude by some. Our eyes will thank you.

2) "Pls" is not a real word. Please take the time to use real words in your posts such as "please".

thanks!
Bear
JavaRanch Sheriff
[ October 11, 2006: Message edited by: Bear Bibeault ]
+Pie Number of slices to send: Send
P.S. I'll save my "scriplets are so yesterday" speech for another time.
+Pie Number of slices to send: Send
 

P.S. I'll save my "scriplets are so yesterday" speech for another time.


I'd like to hear it. Mixing java with html has made me uneasy from the start. This is a discussion forum. Don't be afraid to discuss. Maybe a few alcoholic beverages will loosen those lips.
[ October 11, 2006: Message edited by: sven studde ]
+Pie Number of slices to send: Send
 

Originally posted by sven studde:

I'd like to hear it. Mixing java with html has made me uneasy from the start. This is a discussion forum. Don't be afraid to discuss. Maybe a few alcoholic beverages will loosen those lips.



Stick around and you'll hear it; loud and often.
No drinks needed.



If you'd like to hear Bear's opinions in long form, he's had several articles published in our Javaranch Journal. You can find links at top of the JSP forum.
They're worth reading.
+Pie Number of slices to send: Send
One thing to note, that throws a wrench into everything, is that at deployment time, there really isn't any difference between Servlets, JSPs and for that matter, Java.

JSPs are simply designed and developed differently from Servlets. However, when JSPs run on the server, the server turns the JSP into a Servlet, and runs the JSP with all of the semantics associated with Servlets running in the web container. You can actually instruct a J2EE application server to save the code that is generated when a JSP is converted into a Servlet at runtime.

With WebSphere, (I'm not sure about the other implementations), it is actually a Servlet running on the server that turns JSP files into Servlets. I alway refer to it as the "BorgServlet", although the name IBM uses is much less creative.

Cheers!

-Cameron McKenzie
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1125 times.
Similar Threads
servlet error
session problem in tomcat 5.0.30
How to start EJB?
How to find out cgi variables in java?
Is it true that JSP creates Servlet java code ?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 22:13:36.