jQuery and JSP

forums UseR

Ranch Hand

Posts: 169

posted 7 years ago

Hello,

I am new to jQuery. Can anybody let me know how to use jQuery with JSP? Can anybody post sample code or give design advice.
I have to use JDBC to access MS SQL database. and make the UI more flexible (using JSP, jQuery, Java Beans).

An Ajax request, whether issues by jQuery or not, is like any other request. You can use Servlets, JSP, JDBC or any other technology on the server and the jQuery/Ajax code could care less. All that matters is what's returned as the response.

Bear Bibeault wrote:An Ajax request, whether issues by jQuery or not, is like any other request. You can use Servlets, JSP, JDBC or any other technology on the server and the jQuery/Ajax code could care less. All that matters is what's returned as the response.

Thanks for your response Bear Bibeault. I am reading your book "jQuery in Action". The labs are very nice and complement the theory.

The web app am working on, is just a read only. Searches the table and returns ResultSet (on average 100-150 records).

The difficulty is how/where to start. So far I have a JSP that uses beans to execute JDBC.

You can easily load pre-formatted HTML fragments (including tables) into the DOM with the jQuery load() method.

Let's say that you have a <div> element that will contain the table. You'd write something like:

This would create a request to the controller. The controller would access the model layer to obtain the data necessary to create the table, it would forward to a JSP that would create the HTML fragment for the table, which gets returned as the response (which jQuery injects into the <div>).

This would create a request to the controller. The controller would access the model layer to obtain the data necessary to create the table, it would forward to a JSP that would create the HTML fragment for the table, which gets returned as the response (which jQuery injects into the <div>).

Bear Bibeault wrote: forward to a JSP that would create the HTML fragment for the table, which gets returned as the response (which jQuery injects into the <div>).

Mark Reyes

Ranch Hand

Posts: 426

posted 7 years ago

1

Can anybody give me example/sample code/architecture advice

Hi Srinivas,

I started learning about Ajax in June this year. I learned a lot from this site. Its free so you can freely download them. Examples are in Servlet and JSP so you will be at home in learning them. I think before you start questioning how to use Jquery and updating with DOM, you need to have a basic understanding of how AJAX works. The format on how to send back your data from JSP/Servlets is discussed also there. You can use HTML Fragments/XML/JSON.

Is DWR (direct web remoting ) relevant in my situation?

I used Spring MVC as my backend and I studied how DWR comes into the Ajax Feature but I find it a little obtrusive (*that's my opinion*) so I used jquery and sending response from the backend is just a matter of using libraries such as GSON/Spring-JSON if Spring is your case..

As for Jquery, your book Jquery In Action is an excellent one. Be sure to do the lab page.

Plus folks around here are very nice especially the Guru's(Bear,David,Gregg,Eric) so be sure to be back when you have some questions.

Yes, it does. You're not understanding. There's a lot of foundational concepts about how HTML/JavaScript work that I believe you're missing. When you provide an on click handler for something like a link or submit button (something that triggers a page redirect / POST), if you don't want that default behavior to occur, you need to tell your on click hander to return false.

You're trying to walk a bit while you can't crawl all that well. You're going to continue to struggle unless you get some core knowledge about how things work.

forums UseR

Ranch Hand

Posts: 169

posted 7 years ago

Bear Bibeault wrote:Why are you not using jQuery to establish the handler? If you are going to use jQuery, use jQuery.