Load a JSP File using JQuery in One Line

Here is how to load a JSP file using JQuery in a single line!. The following is a hello world JSP example which will be loaded on a button click using the JQuery. As you can see from the image, the paradigm, write less, do more. is exactly exemplified here.

Project structure

Folder: C:\Program Files\Apache Software Foundation\Tomcat 8.0\webapps\jq_jsp
    +-- index.html
    +-- hello.jsp


<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
// When the document is ready..
// When any element with input tag is clicked
// execute the following function
// Get object of element with loadHere id
// And in it load the hello.jsp file!
<title>Load a JSP File in JQuery</title>
<input type="button" value="Get hello"/>
<div id="loadHere"/>


response.getWriter().println("Hello world!");

The greatest appreciation you could give me is sharing this article. I would sincerely appreciate it :)

Posted by at on

Tags: Java Server Pages, JQuery,