JSP page: JavaScript code
- VaR clienttel = $ ("# clienttel"). Val ();
- VaR activityid = $ ("# activityid"). Val ();
- $. Ajax ({
- Type: "Post", // sending Method
- URL: "/arweb/Reserve/savecode. Action", // path
- Data: "clienttel =" + clienttel + "& activityid =" + activityid,
- Success: function (text) {$ ("# randomcode"). Val (text );},
- Error: function (text) {alert ("sorry, the user ID does not exist. Please enter the correct user ID ");}
- });
VaR clienttel = $ ("# clienttel "). val (); var activityid = $ ("# activityid "). val (); $. ajax ({type: "Post", // sending Method URL: "/arweb/Reserve/savecode. action ", // path data:" clienttel = "+ clienttel +" & activityid = "+ activityid, success: function (text) {$ (" # randomcode "). val (text) ;}, error: function (text) {alert ("sorry, the user ID does not exist. Please enter the correct user ID ");}});
Action class: Java code
- Httpservletresponse res = servletactioncontext. getresponse ();
- Res. Reset ();
- Res. setcontenttype ("text/html; charset = UTF-8 ");
- Printwriter PW = res. getwriter ();
- PW. Print (random );
- PW. Flush ();
- PW. Close ();
Httpservletresponse res = servletactioncontext. getresponse (); Res. reset (); Res. setcontenttype ("text/html; charset = UTF-8"); printwriter PW = res. getwriter (); PW. print (random); PW. flush (); PW. close ();
PW. print (random); here the random is the value that action will pass to JSP. In JSP, success: function (text) here the text is the value that receives the data from the action.