1

I want to submit data from a html page to java class. I am using javascript to get data from html page, now I want to send this data to java class to save this data to db. I am using ftl template to generate html so I cant use jsp here. Please give an example using either javascript of ajax or jquery.

thanks.

1
  • By 'java class' you mean a java servlet? Commented Mar 11, 2011 at 10:37

1 Answer 1

4

You can use jquery to send an ajax request to your Java servlet.

$.ajax({
   type: "POST",
   url: "/app/servlet/",
   data: {name : "John", location : "Boston"},
   success: function(msg){
     alert( "Data Saved: " + msg );
   }
 });
Sign up to request clarification or add additional context in comments.

2 Comments

data: {name: 'John', location: 'Boston'} would be much nicer.
Actually I am developing a plugin which concist of ftl and core java classes not servlets so I cannot use the ajax the way you suggested. Please let me know if there is another way round to pass javascript variables value to java, may be we could pass javascript varibles value to ftl variable and then pass that ftl variable to java class

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.