tags:

views:

54

answers:

2

i need to know the way for call a function in jsp?

in my function, i wrote a code for get user input and write it in xml file... when i call it, there is a error... how could i achieve this.?

<form method = "post" action="Result.jsp" >
<input type="submit" name="submit" value="Submit" onclick="writeXml()"/>
+2  A: 
  1. Place your function (method) in a class that extends HttpServlet
  2. map your servlet in web.xml
  3. make action="/yourServletMapping"
  4. process the submit in the doPost(..) method

But first, read some servlets tutorial.

Update: place the jena jars in WEB-INF/lib

Bozho
I added jena jars to the project after create a project. should i need to add in web - inf/lib again ?
when i call the same thing in main function , it's working properly.. i need to put them in to function and call it in jsp...where is wrong?
adding the jars in your project doesn't mean they are in `WEB-INF/lib` - make sure they are indeed there
Bozho
i can't add jar files again. bz it's already there in the build path ??
classpath of your IDE != classpath of the webapp. Did you check `WEB-INF/lib` ? And how are you deploying your app on tomcat? WTP? using a war file?
Bozho
problem solved.. i added jar files in to that folder.. thanks
+1  A: 

You are trying to call a java method in HTML/JSP. This cannot be done.

When you write a JSP, and "access" it in a browser, the server (like Tomcat) will "process" the JSP and pass the "output" to the browser. The browser sees only HTML/CSS/Javascript and no java code.

The onclick is called by the browser, so the java method cannot be called here.

You need to submit the form to servlets - something like "pass control to servlets" and from there you can call java methods..

Write a servlet. In the onclick event, submit the form. And follow Bozho's advice. (As he said, please read some tutorial on Servlets)

EDIT: BTW, the exception you had mentioned is NOT because of this. There is something else wrong. And to find out what is wrong, we need more details from you. Apart from the JSP what else do you have? Read the complete exception stack trace. Does it mention any of your classes?

Nivas
i try to add a OWL file with the user input.when user input some thing it should write in xml..i get the user input and call a writeXml() function that i mentioned earlier.it gives that error..???
Wait, i dont think I understand. Do you say that the exception occurs when you click the button? I dont think so.Are you using a server? which one? And where do you see this exception stack trace?
Nivas
yep ,when i click the button that error will prompt. i used tomcat and used ECLIPSE as a IDE