I am using SWT browser in my application
I have edited SWT source code according to my need, Now I want a feature of view web page source code by click on button
I have managed "Go to Home page " like this
public void goHome() {
int[] rgdispid = auto.getIDsOfNames(new String[]{"GoHome"});
int dispIdMember = rgdispid[0];
auto.invoke(dispIdMember);
}
I want to know if there is any string for "view page source" like "GoHome"
Or is there any other way to do this.
Thanks in advance
Based on the API of the SWT Browser, looks like you can get the HTML of the page by calling the getText() method.
Eclipse SWT Browser API
Related
I want to have something like this:
public void setButton(){
document.getElementById('scan').disabled=false;
}
scan is the ID of the button in the JSP.
What you are dealing here is html and javascript and not java. Java based systems at the server will generate the html/css/js based code (after executing the JSP) and send it to browser. For enable/disabling and disabling the buttons, use javascript.
Not sure what you use case is, but you can use following javascript code code to enable/disable the buttons
document.getElementById("scan").disabled = true;
This can be called on any event (like page load etc)..
EDIT:
In light of new requirement (Capture USB events), this may not be as straightforward as it seemed. I would suggest following approach.
Write a signed Java Applet. This Applet will use some USB interfacing APIs (e.g jUSB) to listen to the USB plugin events.
Then, from this Applet use Applet Javascript interaction to call the javascript function to enable the button (assuming that the button is disabled when the page loaded).
So it works as follows
When you hit the URL, browser loads the page and Applet (with Scan button disabled by default)
You plugin the USB device
Java code in the applet listens to this event
The listener calls the Javascript function in the page which enables the Scan button.
All the HTML in JSP compiles on server side and comes to Client.
If you want to do something you need to make a request.
You can do it directly with html in your jsp
<input type="button" name=myButton id="scan" value="disable" disabled>
If javascript
document.getElementById("scan").disabled=true; //not false
maybe you can use this
document.getElementById("scan").disabled = true;
or jquery
$("#scan").disable = true;
There is an application that stores photos in oracle db (oracle multimedia format). There is a JAVA servlet page that handle the connection and the SQLs ..., and there are JSP pages to show the images in browser.
There is a delete function in the JAVA page, when i click one thumbnail it navigates to the an other JSP and show the full size image. Here i would like to call the
public void deleteRowById( String selectId ) function which is in the JAVA servlet page. i would like to use a button, and i'm not realy know what is the proper way to call this function.
Any suggestions are welcome.
In the mean time i solved the situation. There is a java class that contains SQL statements -taht's what i would like to call with a form button.
1st JSP page show the button like delete, it navigates to an other JSP page via passing a parameter with post method, in this 2nd JSP page i call the main java class method that execute a delete statement then from the 2nd JSP page i navigate back with <jsp:forward page="1st_page.jsp"/>
Maybe not a cutting edge solution but works like charm :)
I m trying to access JavaScript function from Servlet code. But I'm getting the error shown below.
Here is the code:
out.println("<FRAME src=\"javascript:parent.newWindow('" + URL+ "') \" scrolling=No noresize />");
And this is the error that occurs in JavaScript:
Object does not support this property or method;
You can't access a Javascript function from your servlet code. Javascript executes on the client (= your user's browser) and the servlet code executes on your server (for example Tomcat, JBoss, whatever you're using).
What are you trying to accomplish with your code? I'm sure there's a simpler way to do it than what you just described.
[edited]
I see you just updated your description, so here's my view:
I'm guessing that you want to display a page to the user and when the page is displayed, you want to open a new window which will display another page using the URL parameter to point its address. If this is the case, you should probably just do this in the first page's onLoad() Javascript event using window.open().
There is no newWindow property on a window object (which is what parent references), so this is not unexpected.
Maybe you are looking for the open method instead?
If so, then:
Putting it as the src of an iframe is a very strange thing to do
It will probably be zapped by pop-up blockers
Ok. You try to generate javascript code inside Servlet code. When you do, your code goes to Web browser and it's seen there as a html document with javascript inside. So, your error rather comes from web browser and links to javascript error. Probably it's newWindow method. To open new window you should call window.open() function, I guess.
HtmlUnit for Java is great but I haven't been able to figure out how to view the full source or return the source of a web site as a string. can anyone help me with this?
I know the follow will read the site but now I just want to return the source to a string.
HtmlPage mySite = webClient.getPage("http://mysite.com");
Thanks!
From looking through the API, my thought would be:
mySite.getWebResponse().getContentAsString();
String pageSource = myPage.asXml();
That will get you the full HTML source of the web page.
String pageText = myPage.asText();
That will get you all of the visible text on the page, including line breaks/white space. It would be the same if you were on the page in your browser and Ctrl+A then Ctrl+V into a variable.
have you tried mySite.asXml()? Or you can do mySite.getDocumentElement().toString()
Here is my situation: the user selects a section (for example from a dropdown) such as "Section1," "Section2" or "Section3." Then he clicks the OK button (or some link).
What I need to happen: after he clicks on that button/link, he will be redirected to the selected section, e.g. www.homepage.com/docs#section2.
So far, I have not been able to process the form from Link's onClick method, nor have I been able to call some clickLink on Link from the Button method onSubmit().
I would prefer not to use AJAX or JavaScript. How can I do this?
That's because a Link doesn't submit the form. It just acts as a link to somewhere. To access your formdata you'll need to submit the form first. Try using a SubmitLink instead of a Link and call
getRequestCycle().setRequestTarget
(new RedirectRequestTarget("www.homepage.com/docs#section2"));
from the onSubmit function of the SubmitLink.
Judging from the Javadoc this should work but I can't test it right now.
A RequestTarget that will send a redirect url to the browser. Use this if you
want to direct the browser to some external URL, like Google etc, immediately.
Or if you want to redirect to a Wicket page. If you want to redirect with a
delay the RedirectPage will do a meta tag redirect with a delay.
Did you try Link.setAnchor(Component)?