asp.net mvc - how to submit a form using jquery in jsp -


in asp.net mvc using following snippet can send change password data controller. in controller can cast posted data changepasswordreq object , can our business. looking equivalent of in jsp. how communicate client side server side? want transfer bigger form number of controls.(i using html build pages). appreciable.

 var changereq = { currentpassword: epwd, newpassword: newpwd }  var jsondata = json.stringify(changereq)              $.ajax({                 type: 'post',                 url: "/account/changepassword",                 cache: false,                 timeout: 10000,                 contenttype: "application/json; charset=utf-8",                 success: function (_results) {                     //do                  },                 error: function (_results) {                    //do                 }             });     [httppost]   public actionresult changepassword(changepasswordreq _changepasswordreq)   {      //do business   }    public class changepasswordreq     {         public string currentpassword { get; set; }         public string newpassword { get; set; }     } 

i have tried following. in case generating controls dynamically. cannot them in controller number of dynamic controls vary. there better way in jsp url routing in asp.net mvc.(better @requestmapping(value = "/changepassword", method = requestmethod.post)) how use jquery in jsp.(please me in client side , server side code)

@requestmapping(value = "/changepassword", method = requestmethod.post)     public string home(@requestparam("currentpasswordtxtboxname") string currentpassword,@requestparam("newpasswordtextboxname") string newpassword, locale locale, model model) { // business } 

i found here.

<script src="http://code.jquery.com/jquery-latest.min.js"></script> <script> $(document).ready(function() {     function savedata() {       var data={username:$("#txtusername").[0].value, currentpassword:  $("#txtcurrentpwd").[0].value, newpassword: $("#txtnewpwd").[0].value }     jsondata=json.stringify(data);    $.get('actionservlet',jsondata,function(responsejson) {            //do response json         });     }); });           //can use jquery post in question </script> 

in server side can parameters as

 protected void doget(httpservletrequest request,httpservletresponse response) throws servletexception, ioexception   {   string username =request.getparameter("username");   string currentpwd =request.getparameter("currentpassword");   string newpwd =request.getparameter("newpassword");  } 

in web.xml file

<servlet>   <servlet-name>actionservlet</servlet-name>   <servlet-class>myproject.actionservlet</servlet-class> </servlet> <servlet-mapping>   <servlet-name>actionservlet</servlet-name>   <url-pattern>/actionservlet/*</url-pattern> </servlet-mapping> 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -