admin管理员组

文章数量:1410674

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

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

Share Improve this question edited Jul 9, 2012 at 19:29 Brandon Buck 7,1802 gold badges32 silver badges51 bronze badges asked Jul 9, 2012 at 19:22 DineshkaniDineshkani 3,0037 gold badges32 silver badges45 bronze badges 3
  • 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 municating with the server when the user interacts with the loaded page. – Brandon Buck Commented Jul 9, 2012 at 19:27
  • Please can u give give me a coding for that – Dineshkani Commented Jul 9, 2012 at 19:29
  • Here's a tutorial on JSP and Ajax – Brandon Buck Commented Jul 9, 2012 at 19:41
Add a ment  | 

3 Answers 3

Reset to default 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

Here use this

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

this will help you to do bination 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 )
      }
    })
  })
})

本文标签: jquerycall a jsp method from javascriptStack Overflow