473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Sneaky way to post to a socket

First let me state upfront that I'm a Java programmer, not a web developer.
Consequently I may be flying a bit wild here...

I have scoured the web and usenet for solutions on how to communicate with a
stand-a-alone Java application from a web page. Sounds like there is no
really good browser independent way other than with applets.

Here is what I am trying to do...

I want to load a document with two frames. The top frame basically just has
a button that says something like "Analyze". The bottom frame is initially
loaded up with some web page. The user may browse around via links in the
bottom frame and go to arbitrary web pages which will be loaded in the bottom
frame.

When the user clicks the "Analyze" button, I want to send the URL in the
bottom frame to my Java application for analysis. Both the application and
the web browser are on the same machine. The analysis is really displayed in
the application, so no real results need be displayed in the browser.

I was thinking about using a form post to post to my application (listening
on a special port). I would use a "hidden" form element to send the url for
analysis. This seems to be pretty much working for me. Here is the form
code:

<form action="http://127.0.0.1:7333/results.html" method="post">
<input type="submit" name="foo" value="Analyze Page">
<input type="hidden" name="url_to_parse" value="someurl">
</form>

So I'm posting to the loopback address on port 7333 where my Java app is
listening. The Java app does get data on the port and reads it and generates
some returned text that does get displayed.

My questions:
1. Is there anything fundamentally wrong with doing this this way?

2. Ideally I'd like the post to not change the web browser display, but if I
don't return something the browser says "The page contained no data". Any
way around this?

3. I seem to need to have the form action post to a (bogus) .html file.
Otherwise the browser thinks it needs to download the result as a file. Is
there a better way to handle this?

4. Eventually, I need to build the page that has the forms and I need to
on-the-fly replace the "someurl" with the url loaded in the bottom frame. I
assume I need javascript to do this. Anyone want to post a code snippet to
do what I need (I really know very little about javascript).

Thanks so much for any help or suggestions.

--
Bill Tschumy
Otherwise -- Austin, TX
http://www.otherwise.com

Jul 23 '05 #1
8 1482
On Thu, 29 Apr 2004 17:15:04 GMT, Bill Tschumy
<bi**@otherwiseDELETE.com> wrote:
My questions:
1. Is there anything fundamentally wrong with doing this this way?
Nope, security makes it difficult.
2. Ideally I'd like the post to not change the web browser display, but if I
don't return something the browser says "The page contained no data". Any
way around this?
return a 204 No Content from your Java App.
4. Eventually, I need to build the page that has the forms and I need to
on-the-fly replace the "someurl" with the url loaded in the bottom frame. I
assume I need javascript to do this. Anyone want to post a code snippet to
do what I need (I really know very little about javascript).


Securirty will stuff you.

onclick="this.form.elements['url']=parent.frames[1].location" in the
submit button, but unless you get some security modifications to the
browser to allow that cross domain scripting it isn't going to work.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 23 '05 #2
"Bill Tschumy" <bi**@otherwiseDELETE.com> wrote in message
news:sK*******************@newssvr22.news.prodigy. com...
First let me state upfront that I'm a Java programmer, not a web developer. Consequently I may be flying a bit wild here...

I have scoured the web and usenet for solutions on how to communicate with a stand-a-alone Java application from a web page. Sounds like there is no
really good browser independent way other than with applets.

Here is what I am trying to do...

I really think a hidden applet in your top frame is the way to go.

The Applet must have allowscripting = true, and a public method that
accepts a string.

Then from your analyze button, you call the applets public method with
the bottom frames URL as a parameter from JavaScript.

As you are primarely a java programmer, you already know how to send
your data from the applet to your java-application on your server.

I want to load a document with two frames. The top frame basically just has a button that says something like "Analyze". The bottom frame is initially loaded up with some web page. The user may browse around via links in the
bottom frame and go to arbitrary web pages which will be loaded in the bottom frame.

When the user clicks the "Analyze" button, I want to send the URL in the
bottom frame to my Java application for analysis. Both the application and
the web browser are on the same machine. The analysis is really displayed in the application, so no real results need be displayed in the browser.

I was thinking about using a form post to post to my application (listening on a special port). I would use a "hidden" form element to send the url for analysis. This seems to be pretty much working for me. Here is the form


<snipped />

/Dag.
Jul 23 '05 #3
On Thu, 29 Apr 2004 15:23:14 -0500, Dag Sunde wrote (in article
<Su*********************@juliett.dax.net>):
"Bill Tschumy" <bi**@otherwiseDELETE.com> wrote in message
news:sK*******************@newssvr22.news.prodigy. com...
First let me state upfront that I'm a Java programmer, not a web developer.
Consequently I may be flying a bit wild here...

I have scoured the web and usenet for solutions on how to communicate with

a
stand-a-alone Java application from a web page. Sounds like there is no
really good browser independent way other than with applets.

Here is what I am trying to do...


I really think a hidden applet in your top frame is the way to go.


How do you hid the applet. Does it just have zero width and height?

The Applet must have allowscripting = true, and a public method that
accepts a string.
I'm not familiar with any allowscripting property. Is this something in the
applet tag?

Then from your analyze button, you call the applets public method with the
bottom frames URL as a parameter from JavaScript.
Can you give me an example of how to do this? I'm really not a javascript
person.

As you are primarely a java programmer, you already know how to send your
data from the applet to your java-application on your server.
Yes, I can handle this part.

Thanks for your help.

I want to load a document with two frames. The top frame basically just

has
a button that says something like "Analyze". The bottom frame is

initially
loaded up with some web page. The user may browse around via links in the
bottom frame and go to arbitrary web pages which will be loaded in the

bottom
frame.

When the user clicks the "Analyze" button, I want to send the URL in the
bottom frame to my Java application for analysis. Both the application and
the web browser are on the same machine. The analysis is really displayed

in
the application, so no real results need be displayed in the browser.

I was thinking about using a form post to post to my application

(listening
on a special port). I would use a "hidden" form element to send the url

for
analysis. This seems to be pretty much working for me. Here is the form


<snipped />

/Dag.


--
Bill Tschumy
Otherwise -- Austin, TX
http://www.otherwise.com

Jul 23 '05 #4
On Thu, 29 Apr 2004 14:45:02 -0500, Jim Ley wrote
(in article <40****************@news.individual.net>):
On Thu, 29 Apr 2004 17:15:04 GMT, Bill Tschumy
<bi**@otherwiseDELETE.com> wrote:
My questions:
1. Is there anything fundamentally wrong with doing this this way?
Nope, security makes it difficult.
2. Ideally I'd like the post to not change the web browser display, but if
I
don't return something the browser says "The page contained no data". Any
way around this?


return a 204 No Content from your Java App.
4. Eventually, I need to build the page that has the forms and I need to
on-the-fly replace the "someurl" with the url loaded in the bottom frame.
I
assume I need javascript to do this. Anyone want to post a code snippet
to
do what I need (I really know very little about javascript).


Securirty will stuff you.

onclick="this.form.elements['url']=parent.frames[1].location" in the
submit button, but unless you get some security modifications to the
browser to allow that cross domain scripting it isn't going to work.


I feel I am really close on getting this to work. How is this cross domain?
Everything is happening on the local machine. Is this the same as:

onclick="this.myform.url.value=parent.main.locatio n.href"

if the form is defined as:

<form name=myform action="http://127.0.0.1:7333/results.html" method="post">
<input type="submit" name="foo" value="Download source on page" >
<input type="hidden" name="url" value="ffff">
</form>

Does the onclick go in the submit button's input tag?

Jim.


--
Bill Tschumy
Otherwise -- Austin, TX
http://www.otherwise.com

Jul 23 '05 #5

"Bill Tschumy" <bi**@otherwiseDELETE.com> wrote in message
news:Vy*******************@newssvr22.news.prodigy. com...
On Thu, 29 Apr 2004 15:23:14 -0500, Dag Sunde wrote (in article
<Su*********************@juliett.dax.net>):
"Bill Tschumy" <bi**@otherwiseDELETE.com> wrote in message
news:sK*******************@newssvr22.news.prodigy. com...
First let me state upfront that I'm a Java programmer, not a web
developer. Consequently I may be flying a bit wild here...
.... I really think a hidden applet in your top frame is the way to go.
How do you hid the applet. Does it just have zero width and height?


Yes

The Applet must have allowscripting = true, and a public method that
accepts a string.


I'm not familiar with any allowscripting property. Is this something in

the applet tag?
Yes, it's in the applet tag, and its proper name is "mayscript='true'".

Then from your analyze button, you call the applets public method with the bottom frames URL as a parameter from JavaScript.
Can you give me an example of how to do this? I'm really not a javascript
person.


<script type="text/javascript">

function invokeDispatcher()
{
var javaApplet;
if (typeof document.getElementById('DispatcherApplet').analyz eUrl !=
'undefined')
javaApplet = document.getElementById('DispatcherApplet');
else
return false;

var url = window.top.frames['mainFrame'].location.href;
javaApplet.analyzeUrl(url);
return true;
}

</script>
....
<applet
codebase = "."
code = "com.dagsunde.dispatcher.Dispatcher.class"
id = "DispatcherApplet"
name = "DispatcherApplet"
width = "5"
height = "5"
hspace = "0"
vspace = "0"
align = "left"
mayscript="true" </applet>
<input id="analyzeButton"
type="button"
value="Analyze"
onClick="invokeDispatcher();" />

As you are primarely a java programmer, you already know how to send your data from the applet to your java-application on your server.


Yes, I can handle this part.


BUT! Jim Ley is of course right. JS security stops you when the content in
the frame you're trying to analyze origins from a different domain than the
frame with the script is in.

the line:
var url = window.top.frames['mainFrame'].location.href;

from the script above works fine as long as "mainFrame" contains a document
from
the same server, but gives a "Permission denied" if it is ie. from
google.com

You *might* be able to work around this by digitally signing your script
with a
code signing certificate from Thawte or Verisign... (Costs US$400.- a year)

I'll try it later, and inform you...

--
Dag.

Jul 23 '05 #6
Bill Tschumy <bi**@otherwiseDELETE.com> wrote in message news:<9F******************@newssvr22.news.prodigy. com>...
I feel I am really close on getting this to work. How is this cross domain?
Everything is happening on the local machine. Is this the same as:
Doing it across domains will slam you into the "same origination
policy" I was writing an app that would let people surf in one
window, and bookmark pages in another. But could not even read
the URL of a page that came from a different domain.

Sorry to rain on your parade. The obvious workaround is to have
the user copy and paste the url... but if the page is in a
different frame... you can't always see the url. But you could
use two windows... One where the page to be analyzed is, and
the other where your app is. Copy and paste from one window
to the other. I hated having to do it that way, but got over
it when the app started taking shape.
onclick="this.myform.url.value=parent.main.locatio n.href"

if the form is defined as:

<form name=myform action="http://127.0.0.1:7333/results.html" method="post">
<input type="submit" name="foo" value="Download source on page" >
<input type="hidden" name="url" value="ffff">
</form>

Does the onclick go in the submit button's input tag?


I'd not use a type=submit, but rather a type=button, and in
that tag, do "onclick=myfunction()". The myfunction() function
would validate and submit the form. But that's just my style,
because when you hit 'enter' in any field on a form, it
immediately fires the submit button. So I use a button type
button, then validate, then submit the form.
Jul 23 '05 #7
On Thu, 29 Apr 2004 20:48:43 -0500, Razzbar wrote
(in article <c4*************************@posting.google.com> ):
Bill Tschumy <bi**@otherwiseDELETE.com> wrote in message
news:<9F******************@newssvr22.news.prodigy. com>...
I feel I am really close on getting this to work. How is this cross
domain?
Everything is happening on the local machine. Is this the same as:


Doing it across domains will slam you into the "same origination
policy" I was writing an app that would let people surf in one
window, and bookmark pages in another. But could not even read
the URL of a page that came from a different domain.

Sorry to rain on your parade. The obvious workaround is to have
the user copy and paste the url... but if the page is in a
different frame... you can't always see the url. But you could
use two windows... One where the page to be analyzed is, and
the other where your app is. Copy and paste from one window
to the other. I hated having to do it that way, but got over
it when the app started taking shape.


I appreciate everyone taking time to explain the issues to me. I think I'll
adopt a totally different approach to this.

--
Bill Tschumy
Otherwise -- Austin, TX
http://www.otherwise.com

Jul 23 '05 #8
"Razzbar" <gl***@potatoradio.f2s.com> wrote in message
news:c4*************************@posting.google.co m...
Bill Tschumy <bi**@otherwiseDELETE.com> wrote in message
news:<9F******************@newssvr22.news.prodigy. com>...
I feel I am really close on getting this to work. How is this cross
domain?
Everything is happening on the local machine. Is this the same as:


Doing it across domains will slam you into the "same origination
policy" I was writing an app that would let people surf in one
window, and bookmark pages in another. But could not even read
the URL of a page that came from a different domain.

Sorry to rain on your parade. The obvious workaround is to have
the user copy and paste the url... but if the page is in a
different frame... you can't always see the url. But you could
use two windows... One where the page to be analyzed is, and
the other where your app is. Copy and paste from one window
to the other. I hated having to do it that way, but got over
it when the app started taking shape.
onclick="this.myform.url.value=parent.main.locatio n.href"

if the form is defined as:

<form name=myform action="http://127.0.0.1:7333/results.html"
method="post">
<input type="submit" name="foo" value="Download source on page" >
<input type="hidden" name="url" value="ffff">
</form>

Does the onclick go in the submit button's input tag?


I'd not use a type=submit, but rather a type=button, and in
that tag, do "onclick=myfunction()". The myfunction() function
would validate and submit the form. But that's just my style,
because when you hit 'enter' in any field on a form, it
immediately fires the submit button. So I use a button type
button, then validate, then submit the form.


couldn't you write a short php script to get the requested info from the
domain instead...then it would be comming from your domain right?
Jul 23 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Christian Galbavy | last post by:
Hello! My friend and I are working on a little program. It sends a local file to a server (php), we use the rfc1867 protocoll for this. When the server gets the data, it replies with some...
4
by: michaelparkin | last post by:
Hi, Sorry to post what might seem like a trivial problem here, but its driving me mad! I have a simple https client that uses httplib to post data to a web server. When I post over http &...
3
by: Mike Chirico | last post by:
For a C http_post example ref: http://souptonuts.sourceforge.net/code/http_post.c.html Regards, Mike
11
by: livin | last post by:
I need to post form data to an ASP page that looks like this on the page itself... <form method='POST'><input src=\icons\devices\coffee-on.gif type='image' align='absmiddle' width=16 height=16...
6
by: Heavy | last post by:
Ciao a tutti, sto creando una applicazione in python, che deve fungere anche da server web... non ho assolutamente problemi a prendere i parametri di una 'GET', mi limito a fare il parsing della...
2
by: rup | last post by:
Hello, This is my first application on socket programming in vc++. I am facing problem that how to make connection to server, & make GET/POST request by HTTP. Please help me. Its urgent.......
56
by: UKuser | last post by:
Hi, I'm not sure if this can be done as I've searched the web and this forum. I am using an online merchant provider and I must post certain variables to their webforms through a form on my...
4
by: Wolfgang Draxinger | last post by:
I'm thinking about writing a script to upload videos to sites like YouTube or Google Video, which is usually done by a HTTP POST. The problem is, that videos, by nature are rather big files,...
0
by: GeicoGecko | last post by:
Hey guys, There was no python section in the "Web Development" forum so I'm hoping I can pose my question in here. Our system We currently have a python webserver using SimpleHTTPServer,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.