Sorry if this is a stupid question. I was following the 'Networking Client Applet Example' found at http://docs.oracle.com/javase/tutorial/deployment/applet/clientExample.html. However, I am having trouble figuring out how to implement step 7:
*7. Open the web page containing your applet in a browser by entering the URL of the web page. The host name in the URL should be the same as the name of the host on which the server-side application is running.
For example, if the server-side application is running on a machine named JohnDoeMachine, you should enter a similar URL. The exact port number and path will vary depending on your web server setup.
"http://JohnDoeMachine:8080/quoteApplet/quoteApplet.html"
The QuoteClientApplet will be displayed on the web page.*
We are asked to open the web page containing the applet by entering the URL of the web page. I understand where quoteApplet comes from, but how am I supposed to find out the http address and port number of the web page? It says that the port number and path will vary depending on my web server setup. How do I set it up? Do I have to use a host web server like apache?
Yes, they're asking you put the files on a web server somewhere. If you have a hosting account, you could upload it there. Otherwise, you could install a web server like apache on your own computer(recommended for testing).
Each web server has different install instructions, but generally you install it and have it listen on port 80, which is probably the default config for most web servers. They're example assumed you have the webserver listen on port 8080
If you have the webserver listen on port 80, then url to use in your browser would be something like
http://localhost/quoteApplet/quoteApplet.html
You can omit the port in the url if its port 80. localhost is a special address that always points back to your own computer.
The reason they ask you to install a web server has to do with javas security model - if you use a browser to load the web page from the filesystem instead of from a url, java wont let you open socket connections to other domains unless you edit the java policy file - and this gets more complicated.
It says right on that page:
2 . Include the following HTML code in a web page to deploy QuoteClientApplet.
<script src="http://www.java.com/js/deployJava.js"></script>
<script>
var attributes =
{ code:'QuoteClientApplet.class', width:500, height:100} ;
var parameters =
{codebase_lookup:'true'};
deployJava.runApplet(attributes, parameters, '1.6');
</script>
You can host that web page in any webserver you like, this applet will run in the browser, not serverside.
Related
I need some advice in the following matter:
I have two machines that are connected via ethernet.
One machine (lets call it ServerSide) is also connected to the Internet via LAN. The second machine (ClientSide) is offline, in the beginning.
So ServerSide is creating a webserver with Jetty on port XY. ClientSide opens a webbrowser and requests some page (e.g. stackoverflow.com). The request will be forwarded to port XY and the webserver. ServerSide would have to send the request to the internet and then back over ServerSide to ClientSide, so the webbrowser should display the requested webpage.
Is it even possible to do that this way?
Thanks in advance
Yes. What you need on server side is an HTTP Proxy and there are plenty of existing solutions in the market.
Check out the Wikipedia article about proxies. Bear in mind that the client might require some configuration (Proxy settings) so that it forwards the requests to the proxy rather than attempting to reach the final host.
I have developed a REST based web service that works perfectly on my machine. The URL is
http://localhost:8080/MyRESTProject/resources/welcome/
Obviously, the URL would work only on my machine. What I want is the URL to work on any remote machine. Also, I want the service to run constantly. Is this possible even after I terminate the web service process?
PS: I am using eclipse dynamic web project to build this web service and the OS is windows 7.
Your web service will be available as long as it is being hosted. A web server receives HTTP requests and replies with HTTP responses. How can you expect your web service to continue working if you terminate the server process?
As for your web service being accessible from outside, you will need to know the public IP address of your network. You can search "What is my public IP" on Google search to get your answer.
But you are not done yet, you will need to configure your router/firewall to open up a port on your router and map it to port 8080 on your host.
I have developed a Play! 1.2.7 web application which calls an existing online payment service, eclipsified to work in Java.
I send data in POST to a servlet and get a response in GET to my application. This is possible because one of the data sent to the service is the URL of my controller handling the response.
I had this working perfectly in local environment but when I move the webapp to a Tomcat container on our local server with public ip I'm stuck because service response cannot find my webapp as it used to do with localhost.
Locally the URL was something like
http://localhost:port/myAction
When I put it on tomcat I changed the URL to
http://my.public.ip.address:tomcat_port/app_name/myAction
I get the "page is not available" message from browser.
My guess is that I miss some basics from network communication and I'd like to know how to have this working when the application is deployed on our server.
Ps. sorry for bad tagging, I'm not sure what's this question's target
EDIT: no logs from catalina.out. If I run the application nothing gets logged
I came across the solution by knowing that loopback is not enable by default on every router.
So I will never be able to have a response client side when I send the request from the lan where the server is located, unless loopback is enabled on the router.
To test my application I had to use the server local address, visible from inside.
I am trying to connect to a database on my website from a java applet.
When I try from eclipse, it says that there was a communications link failure and that the driver has not received any packets from the server. Is that because only applets on the actual server can connect to a database?
So I exported it as a jar and I personally signed it and uploaded it to my website. Then using as embed tag, I put it in my webpage.
<div id="blah">
<embed id="Math"
type="application/x-java-applet"
width="810" height="600"
archive="mathG.jar,mysql-connector-java-5.1.23-bin.jar"
code="com.mathg.math.MathG"
codebase="test"
pluginspage="http://java.com/download/"/>
Is that the proper way to put the applet on the site? The applet shows up and it works on the webpage, but when I press a button to connect to the database, it says that it couldn't connect.
I tried using both localhost and the actual ip in my java code to try to connect, but neither works.
Putting the IP address of the database server is preferred; localhost should only be used for quick & dirty local tests. It's unlikely that you'll deploy an app or database on localhost.
This is a very bad idea. No applet should have direct access to a database from the internet. All that data is exposed.
A better idea is to put a servlet in-between the applet and database. Deploy the servlet by exposing it to the internet; put the database behind a firewall and only open its port to the servlet. Let the servlet handle authentication, validation, binding, and interacting with the database. Users will be much better off with this design.
i need to send a request to a website when a user submits their url, i tried using curl but it uses server ip which i dont want i have seen a website that is doing a similar job by using applet, users need to open a popup which contains the applet after they leave it open allow it to run it uses a port and then uses the localhost ip like so 127.0.0.1:64653 to send request and basicly curl by the user ip. i decompiled the applet the website was using and they were using java.net.ServerSocket and some other java code but i do not know anything about java. I would to know how this can be done.
I think you are really confused.
a user does not have a URL.
there is a IP address that
represents the browser end of the
connection to the web server he/she
is connected to (actually, there
could be more than one) but this
does not allow something else to
establish a connection to the
browser. So it is not a URL.
the IP address + port number
that the browser has are transient.
In 2 minutes time, the very same
IP/port could denote a different
user, possibly even on a different
machine.
127.0.0.1 is a "special" IP
address that says "this machine".
It cannot be used for communication
with another machine.
notwithstanding all of the
above, web browsers do not accept
incoming HTTP connections from web
servers or anything else. The HTTP
protocol (which is what the web
works on) distinguishes between the
roles of "client" and "server", and
specifies that a client connects to
a server and not the other way
round. A web browser is always an
HTTP client, by convention and also
for security reasons.
So when you say ...
i need to send a request to a website when a user submits their url
... it simply does not make any sense. Please explain what you are tying to achieve ... not how you are trying to achieve it ... and we might be able to help.