Reputation: 850
I am working on a web app, where a EXTJS makes an ajax call to a JSP, the JSP in turn calls a java class and then returns the value and updates something in the database.
now the question is, I somehow do not feel this is an effective way, I discovered about servets working and was wondering if should just make a Ajax call to the servlet instead of JSP. Are there any other ways which are better and optimized. Please explain.
Thanks, SixthString
Upvotes: 0
Views: 800
Reputation: 10072
It depends on what you want returned form your Ajax call. JSP is used for generating formatted HTML. If that's what you're looking to get from the Ajax call, then JSP could be the right choice.
If you're looking for some raw data, then you might as well skip the JSP template and go straight to the servlet. I recommend using JSON in this case, because it's easy to work with in JavaScript.
Upvotes: 1
Reputation: 20371
You're right - a Servlet
is better suited for situations like there where all you really need is data from a web end point. The purpose of JSP
technology is presentation, there really shouldn't be any business logic in a JSP
if you can help it. JSP
s are usually employed as the V
in MVC
(Model-View-Controller
) - a design pattern that advocates separating the presentation from the control and business logic. So in theory, if you did everything just right, you would be able to swap out one view for another with minimal work since the view just presents the information.
Do note that JSPs are eventually compiled into Servlets themselves so the issue isn't one of a technical limitation but more of a good design/programming practice.
Upvotes: 2