Applet - Servlet Communication Issue
Hello everyone,
I am trying to design a login page using an applet. This applet will collect the user name and password and send them to a servlet inside Apache WebServer. This servlet is supposed to redirect to another applet (either an admin applet or any local user applet) if the login information is correct after checking in database (MySQL) or to an error HTML page if anythig goes wrong.
now the problem is that i am unable to redirect to another applet using the servlet . the login applet is invoked with the help of an html page and is executed under http web server. the applet is comming perfectly and i can also send any string value to the servlet and echo them back...but i am unable to make the servlet redirect to any other applet or web page. no errors are shown.....
i can redirect to another applet using showDocument() method of applet
is it possible to make an applet redirect to another applet or webpage with the help of a servlet ?
will sendRedirect() function works with applets() ?
does java.net class has any limitations that prevents the expected redirection ?
Control Flow
--
1> login_applet
to and from
2>login_servlet to and from 3> Database
to and from
4>choice
a) admin_applet
b)employee_applet
Note: in between i have to pass data in and out between
applet --> servlet
servlet <-- applet
servlet <> database
kindly if possible get me a simple code about how to make these connections and data passing from 1 to 4 and vice versa (only the applet - servlet part coding is expected database, xml coding not necessary but if included then thanks a lot). i am using GEL editor not netbeans due to memory insufficiency and the kind of data i am expecting to pass between will be mostly string types.
# 1
When you do a redirect you are sending an HTTP status code in the response header ( a 302 but I would have to look it up) The browser knows that when it receives this HTTP status code it must make a new request.
In your applet you are probably using the URLConnection class to make the HTTP request to the servlet. When the servlet does the redirect and returns the HTTP status code it is not going to the browser but is going back to the applet. So the browser will not know to make a new request.
What you need to do in the applet is get the response back from the servlet and check the status code. If the code is a 404 or 500 you'll need to display a message to the user. If it is a 302 redirect message you can use LiveConnect to call a JavaScript function in the page's html to set the document's location property to the new location. The address of the location will also be returned in the response header.
In effect you will have to do the redirect for the browser
# 2
thanks a lot for the information... i hope you are trying to say the following
Communication flow
-
1.applet -> request -> servlet
2.servlet --> response -> applet
3.applet >using Live Connect Technology --> JavaScript inside HTML
4.JavaScript inside HTML--> redirect to the new applet or any html page.
i have referred to this LiveConnect concept... and it only confused me... and i am using mozilla firefox... will this LiveConnect works in firefox ?..... since the libraries i read in net are all related to netscape. and if you can give me a sample code i can have a start.....a simple one....such as .....
i want an applet that passes a string via textBox to servlet then the servlet will echo this back to another applet if the string is "hi" else the servlet will display an HTML page printing what we typed in the textBox. using the LiveConnect concept
thank you....