开发者

jsp function call and xml

开发者 https://www.devze.com 2023-01-05 22:29 出处:网络
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 t

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()"/>


  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


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号