Run java applet directly from JAR itself on HTTP server - java

I have the following problem.
I have one JAR file, which includes Main.class and Applet.class. In the Main.class I run HTTP server on port 8888, where is set my handler for com.sun.net.httpserver.HttpHandler. I want to do the following: I want to set Headers Content-Type to Java Applet, so don't send some HTML code, but send the Applet.class to run in the browser. It means, if someone will open the IP address with port 8888, it sends him request to run Applet.class, but it won't send him any HTML. Is this somehow possible?
Could this be solved by Java (.jsp) pages?

No. A browser will not run an applet without an HTML page.
You could write a Java client app that downloads and runs your applet without any HTML, or you could use Java Web Start.

Related

How to save file on server side using applet?

Sir/Madam,
I have design an application using java-applet in that i want to save pdf file on server location i.e http://www.mywebsite/myfolder/ . On local side it will run successfuly but actualy on server side it will not work.
As far as I understand, you would like the applet to store the file on the server. That is obviously not possible because the applet runs on the client. The option I can think of, is to implement an HTTP Post from the applet to the server and handle it on the server.
Short answer: applets run on client side so they save nothing on server.
Longer answer: that applet will have to communicate somehow with a server side-application. I.e. like this SO Q&A.
A question on tech stack: Is it really necessary to use applet? It's obsolete technology. Can't you use a jnlp rich client application? Or a simple webapp?

Is java Web Start Application using my browser each time I run the application?

I would like to know if when I launch my Java Web Start application, I'm using my browser or the connection is directly from the Java sandbox against the server through Http/Https protocol.
I want ot know, wether once the JAR has been downloaded and stored locally, next time when the applciation is launched, it will use my browser?
No, Java WebStart doesn't use the browser. It uses the JRE to connect to a remote server using HTTP or HTTPS.
The browser is only involved in the download of the .jnlp file. And even here, you could send the JNLP file by e-mail or any other mean. It would work too.

Java Networking Client Applet

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.

File upload on server

I have created an applet which creates a file on running it. But when I run my applet via server, it fails.
Is there any possible way to create a file on server with applet?
EDIT:I am creating a sound record applet which works fine when I run the applet in browser locally.It actually creates a file of recorded sound,but when I run the same applet on server,it does not create file.Is it because the server does not allow you to do so?
Is there any possible solution so that the file can be created?
File objects always point to a location (that may not exist) on the client machine.
To store something on a server, it would require some server side functionality to accept the bytes and create a (server-side) File. That might be done with PHP, servlets/JSP, ASP etc. Once the server-side is organized to accept the bytes, the applet can connect to it and push the sound recording through.
Java Applets are run on the client machine. Once you invoke the page containing an applet, the applet gets downloaded to the client's machine and runs. Hence it will not get access to the server.

Reading file on client machine from server

I have added functionality which will enable the user to attach a file from web page.
and this file will be sent as an attachment to another user.
When I try this on my local machine it works fine.
I deployed the application on the server.
And when I am trying to attach a file its throwing FileNotFoundException.
Kindly help.
You seems to be reading file system assuming that client is always on server.
Server and Client are different things. Client may be / May not be [all most all the time] on server. You need to upload file then read..
If you can read client's flle system this easily, then we might not have coined the word security

Categories

Resources