jsp function call and xml
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 开发者_JS百科could i achieve this.?
<form method = "post" action="Result.jsp" >
<input type="submit" name="submit" value="Submit" onclick="writeXml()"/>
- Place your function (method) in a class that extends
HttpServlet
- map your servlet in
web.xml
- make
action="/yourServletMapping
" - process the submit in the
doPost(..)
method
But first, read some servlets tutorial.
Update: place the jena jars in WEB-INF/lib
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?
精彩评论