We want to get an entire page as ajax response by using jquery get method. Steps: 1) First create pages(FirstJsp.jsp and SecondJsp.jsp) 2) call jquery get method to get ajax response in one page(here FirstJsp.jsp to get SecondJsp.jsp) 3)Configure struts.xml file Lets start with page creating FirstJsp.jsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib uri="/struts-tags" prefix="s" %> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>First JSP Page</title> <script type='text/javascript' src="js/jquery.min.js"></script> </head> <body> <h1>Get Html Page As Responser</h1> <s:submit id="fetch" value="fetch" /> <div id="content"></div> <script> $(document).ready(function() { $(document).on("click", "#fetch", function(f) { f.preventDefault(); $.get("getContent", function(data) { $("#content").html(data); }); }); }); </script> </body> </html> |
SecondJsp.jsp
| This is Second Jsp Page</h1> <ol> <li>Create jsp/html files</li> <li>Call ajax method to get response</li> <li>Set configuration file and respond with html/jsp file which you want to get on success</li> </ol> |
Struts.xml
| <package name="default" extends="struts-default"> <action name="getContent"> <result name="success">SecondJsp.jsp</result> </action> </package> |
Output