Should i use jsp or servlets
Some works by Jakob Jenkov on his blog are really amazing too. Struts2 and Spring do become simpler when you know servlets. Hope my answer helps :. Sign up to join this community. The best answers are voted up and rise to the top.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more. Do I need to know servlets and JSP to learn spring or hibernate or any other java web frameworks? Asked 9 years, 2 months ago. Active 4 years, 9 months ago. Viewed 60k times. Improve this question. Note that hibernate is just a database abstraction layer, nothing more, and it can be used to plug a data source into any kind of java app, not just a web application.
An easy to understand read, but also covers a lot. I don't think this question has been answered adequately. Anyone care to show why that may or may not be applicable today? Here is his post - coderanch.
Okay, I got some answers from Bear Bibeault. See these two links - coderanch. Add a comment. Active Oldest Votes. Improve this answer. GlenPeterson GlenPeterson I cleaned up my answer and added links as requested. Most of the other technologies, you know enough about already that you should be able to have working in a few hours or a day. I don't know Spring, but check the documentation on their web site or get a highly rated book on Amazon.
I don't see how this answers the question. Care to show why that may or may not be applicable today? GlenPeterson, "The whole original Struts framework was a single servlet. Wouldn't it make every http call slow? Pacerier We used to load Struts 1 in Tomcat as a servlet. The Struts Controller servlet would send different requests to different threads the same way a web server would, just at the servlet level instead of the container level.
I imagine the overhead was minimal. What tends to be slowest is the database calls. At the time it was popular to use a separate server for static content for speed, so it worked out.
Dynamic 5, 9 9 gold badges 42 42 silver badges 73 73 bronze badges. Ed Griebel Ed Griebel 1 1 silver badge 8 8 bronze badges. In the controller side servlet you implement business logic. The servlet controller usually forward the request to a jsp that will generate the actual html response the View in MVC. The goal is to separate concerns Thousands of books have been written on that subject. But both are technically the same. JSP will be translated into servlet, either in compile time like in JDeveloper or when accessed for the first time like in Tomcat.
So the real difference is in the ease of use. I'm pretty sure that you'll have a hard time rendering HTML page using servlet; but opposite to common sense, you'll actually find it pretty easy to code even a fairly complex logic all inside JSP with the help of some prepared helper class maybe. PHP guys do this all the time. And so they fall into the pitfall of creating spaghetti codes.
So my solution to your problem: if you found it easier to code in JSP and it wouldn't involve too many code, feel free to code in JSP. Otherwise, use servlet. Agreed with all the points above about the differences between JSPs and Servlets, but here are a couple additional considerations. You write:. Your application is consuming the payment service of another application.
Your solution is fragile because if the payment service in the other application changes, that breaks your JSP page. Or if you want to change your application's payment policies, then your page will have to change. The short answer is that your application should be consuming the application's payment service via a web service. Neither a servlet nor a JSP page is appropriate place to put your consumption logic. I would recommend Spring, as it offers you the full stack of what you need from the server pages to web service gateway logic to DAOs.
If you want to understand the nuts and bolts of Spring, I would recommend Spring in Action. If you need to understand better how to tier an enterprise architecture written in a language like Java or C , I would recommend Fowler's Patterns of Enterprise Application Architecture.
Yeah, this should be a servlet. A JSP may be easier to develop, but a servlet will be easier to maintain. Just imagine having to fix some random bug in 6 months and trying to remember how it worked.
In java servlet the HTML tags are embeded in java coding. For big application for big problem the servlet is complex to read,understand,debug,etc because of unreadability of embeding more html tags inside the java coding..
So we use jsp. In jsp it is easy to understand,debug,etc. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. When do you use a JSP and when a Servlet? Asked 13 years, 1 month ago. Active 7 years, 4 months ago. Viewed 67k times. Improve this question. Bill the Lizard k gold badges silver badges bronze badges.
Antony Antony 1 1 gold badge 4 4 silver badges 8 8 bronze badges. Also check answers to stackoverflow. Add a comment. Active Oldest Votes. Improve this answer.
JeeBee JeeBee Bill the Lizard Bill the Lizard k gold badges silver badges bronze badges. There are 2 pretty simple rules: Whenever you want to write Java code business logic , do it in a Java class so, Servlet. Skip to content. Change Language. Related Articles. Table of Contents. Save Article. Improve Article. Like Article. Brief Introduction: A servlet is a Java class which is used to extend the capabilities of servers that host applications accessed by means of a request-response model.
0コメント