java - Ajax call to jsp and jsp redirecting to further jsp -
I am getting an Ajax call on a jsp page which in turn is redirecting based on the value of a flag variable JSP file.
The AJAX call is something like this:
$ Ajax ({url: 'uploadwebcamimage.jsp', type: "post", data: {encodeimg: dataUrl, OwnerId: document.Clickpictures.OwnerId.value, OwnerPhone: document.Clickpictures.OwnerPhone.value, mobilepass: document.Clickpictures. Mobilepass.value, emailpass: document.Clickpictures.emailpass.value, mypassword: document.Clickpictures.mypassword.value, mygroupuserid: document.Clickpictures.mygroupuserid.value}, error: work () {warning ('error');} success : Function (msg) {// warning ((msg)); if (msg) indexOf ("true")> = 0) {// how grouplist location.href = "site_index_groupadmin.jsp res1 =?" + to get the grouplist;} else {warning ("unsuccessful");}}}); And in jsp I have done something like this:
& lt;% ArrayList & lt; String & gt; List = New Arrestist & lt; String & gt; (); String query = "select gmy from tbGroup"; Ps1 = con.prepareStatement (query); RS1 = ps1.executeQuery (); While (rs1.next ()) {list.add (rs1.getString ("GNAME")); } // How can I send this list to my AJAX call? Please help (flag == true) {out.println (flag); } And if (flag == incorrect) {out.println (flag); }% & Gt; but it is not redirected to another page. Please help
How can I send this list to my AJAX call? .
Application / Jason; Charset = UTF-8 "Page Encoding =" UTF-8 "%> & Lt;% // Your List Jason GSon = New GS (); JsonObject Root = New JsonObject (); Root.addProperty ("flag", flag); // Add root.addProperty ("list", gson.toJson (list)); // Add list.printline (gson.toJson (root)); Out.flush (); & Gt%; Provide a list like and AJAX:
$ Ajax ({url: 'uploadwebcamimage.jsp', type: "post", data type: '{encodeimg: dataUrl, OwnerId: document.Clickpictures.OwnerId.value, OwnerPhone: document.Clickpictures.OwnerPhone.value, mobilepass: json' , // datatype, json, ie the data form data formatted as a data format. ClickPictures.mobilepass.value, emailpass: document.Clickpictures.emailpass.value, mypassword: document.Clickpictures.mypassword.value, mygroupuserid: document.Clickpictures.mygroupuserid. value}, error: function (jqXHR, textStatus, errorThrown) {warning (textStatus + ':' + errorThrown);}, success: function (response) {warning (response); $ .eich (response.list, function (key , Value) {warnings (Value);});}}); According to your comment:
Create a servlet instead of writing java code in jsp, and turn on java code such as servlets:
secure Zero doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {ArrayList & lt; String & gt; List = New Arrestist & lt; String & gt; (); String query = "select gmy from tbGroup"; Ps1 = con.prepareStatement (query); RS1 = ps1.executeQuery (); While (rs1.next ()) {list.add (rs1.getString ("GNAME")); } // set flag boolean flag = true; Gsan gsn = new gsan (); Response.setContentType ("application / json"); Response.setCharacterEncoding ("UTF-8"); PrintWriter out = response.getWriter (); Out.written (gsn.tjson (new north zone (flag, list))); Out.flush (); } and looks like the northwest square:
public class ResponseResult {private boolean flag; Private listing & lt; String & gt; List; Public Response Answer () {} Public Response Answer (Boolean flag, list & lt; string & gt; list) {super; This.flag = flag; This.list = list; } // getters and setters} If you want to send a list to any other jsp, then do so in the servlet:
To request if you Go ahead:
request.setAttribute ("list", list); Request Dispatcher Dispatcher = request.getRequestDispatcher ("pagename.jsp"); Dispatcher. Forwarded (request, response); If you redirect again: or using alternate session:
// Session request to add list .getSession () . SetAttribute ("list", list); // It gets back to the second page such as the list & lt; String & gt; myListObject = (list & lt; string & gt;) request.getSession (). GetAttribute ("list");
Comments
Post a Comment