How to pass information between the Javascript code within a WebBrowser and Java code
I have an embedded WebBrowser where I added a LocationListener.
mywebBrowser.addLocationListener(new LocationListener(){
public void changing(LocationEvent event){
event.getLocation()
}
}) ;
In this WebBrowser, I have a form where I can enter text. I also have a link allows the user to navigate to other pages.
<form method="get" action="{$self}" name="addcommentform">
<textarea title="{$enterComment}" name="comment" class="commentarea" </textarea>
<input class="Button" type="submit" value="{$postComment}" />
</form>
My question is, if the user enters the text and then click on some link instead of the submit button, how can I find out what is the text entered by the user ON THE JAVA SIDE? I want to prompt the user from the Javaside with a warning message if he / she has entered some text.
I can't find a way to pass that text entered in this textarea to my code in the java side.
I think the best way to pass the info back is through this e开发者_C百科vent.getLocation() string. But how can I append the text so the event.getLocation() can get such text?
Thanks a lot.
You can get the GET or POST parameters from your Java classes (Servlets, JSPs, Struts actions, etc.).
For example, if you want to get the GET parameter from a Servlet, you can use:
public class ThreeParams extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String comment = request.getParameter("comment");
// Do something with the value
}
}
Have you tried the getDocument() method on the WebBrowser component? I'm not sure if this gets updated in real-time, but it might be worth a look.
精彩评论