3

I use a method in jsp page like this and the page is saved in the name of new.jsp

<%!
    public void createXml(String graph) throws Exception
    {
        try
        {
            String str="dinesh"

            DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
            Document doc = docBuilder.newDocument();
        }

        catch(Exception e)
        {
            System.out.println(e);
        }
    }
%>

If i call this page like this

<form method="post" action="new.jsp">

But, I want to call this method of createXml only using javascript or jquery coding because i am going add various method in the new.jsp. Any one help this to call method without calling the whole jsp page

Brandon Buck
  • 7,177
  • 2
  • 30
  • 51
Dineshkani
  • 2,899
  • 7
  • 31
  • 43
  • I don't think this is possible, you can't directly interface with the server from Javascript so your only solution would be to use an Ajax request or other means of communicating with the server when the user interacts with the loaded page. – Brandon Buck Jul 09 '12 at 19:27
  • Please can u give give me a coding for that – Dineshkani Jul 09 '12 at 19:29
  • Here's a tutorial on [JSP and Ajax](http://www.cs.wcupa.edu/~rkline/Java/ajax.html) – Brandon Buck Jul 09 '12 at 19:41

3 Answers3

2

What you're looking for is how to create an ajax request. You can do it without jquery or easily with jQuery:

$.post('new.jsp',{ param1: 'param1value', param2: 'param2value'},function(data){
    if(data){
        console.log(data); // response from your server
    }
  });

There's a lot more info in the jQuery docs

Community
  • 1
  • 1
bokonic
  • 1,751
  • 10
  • 12
0

this will help you to do combination of ajax jquery jsp

http://www.cs.wcupa.edu/~rkline/Java/ajax.html

have a look

check AJAX HTML data transmission

$(function() {
  $("#button").click(function() {
    $.ajax({
      type: "GET",
      url: "handler/book_table.jsp",
      data: { id: $("#sel").val() },
      success: function(data) {
        $("#out").html( data )
      }
    })
  })
})
zod
  • 12,092
  • 24
  • 70
  • 106
0

Here use this

$.post("new.jsp", { name: "John", time: "2pm" },
function(data){
alert("Data Loaded: " + data);});
Dineshkani
  • 2,899
  • 7
  • 31
  • 43