Hi Nitin,

As suggested by others, it is better to change the design for user
authentication.
But in case the approach you are using could not be changed, then you could
follow the following steps...

Step1: User enters the User Id & Password in the applet text fields and
presses Login button.
Step2: In the button click event add the following line of code.

           String userId = userIdTextField.getText();
           Char[] passwordCharacterArray =
passwordPasswordField.getPassword();
           String password = String.copyValueOf(passwordCharacterArray);

           URL serverUrl = getCodeBase();
           String protocal = serverUrl.getProtocol();
           String serverName = serverUrl.getHost();
           String port = serverUrl.getPort();
           // It is assumed that the servlet is listening to the URL -->
http://ServerName:Port/Servlets/UserAuthenticaterServlet
           URL servletUrl = new
URL(protocal,serverName,port,"/servlets/UserAuthenticaterServlet" +
"?UserId=" + userId + "&Password=" + password);
           password = null;
           getAppletContext().showDocument(servletUrl);

Step3: UserAuthenticaterServlet carry out the authentication part and
outputs the result.
          Extract the UserId and Password from the Url using
getParameter("UserId") and  getParameter("Password"); respectively.
          Validate the user credentials.
          Open the outputstream using OutputStream out =
res.getOutputStream() & send the result back to the client using
out.println().
          The output of the servlet will be displayed in the browser where
the user entered the logon credentials.

Hope this helps....

Regards,
Mahesh


----- Original Message -----
From: Nitin Kulkarni <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, June 09, 2000 6:12 AM
Subject: Re: TECH: Servlets : How to do this: Problem made clearer


> Dear Friends
>
> Thanks for your replies and I am sorry that I did not ask the questoin
> correctly or may be completely. Sorry for a slightly long mail but I am
> trying to make the problem clearer.
>
> I sure know the getAppletContext.showDocument() method. But here I think
> everybody has missed the point that the initial applet is an
authentication
> applet which is supposed to send the userid and password to the servlet
and
> then the servlet generates the next page if the user is authentic user and
> writes to the outputstream which happens to be the input stream of the
> applet. So it is the applet which gets the HTML document and not the
> browser. I sure could have saved the o/p of the servlet in a temp file and
> used the showDocument method of the applet to load this temp file. But
then
> what happens in a multiuser scenario (how many temp files can I create)
and
> more importantly if I use this method what prevents the user from
> bookmarking this page and bypassing the authnetication process the next
time
> he/she visits the site. Even if choose not to create the temp file and
call
> the servlet directly as suggested in the mail below,how do I make sure
that
> the correct page is sent back, because the servlet may develop two
> pages(error page or the next page) and again bookmarking problem is still
> there. Right?
>
>
> I hope I have made the problem clearer now. I am looking for a solution in
> the context of the above problem.
>
> Regards
>
> Nitin
> nitin
>
>
>
>
>
>
>
> >From: David Harkness <[EMAIL PROTECTED]>
> >Reply-To: [EMAIL PROTECTED]
> >To: [EMAIL PROTECTED]
> >Subject: TECH: Servlets : How to do this
> >Date: Thu, 08 Jun 2000 16:01:30 -0700
> >
> >Hi,
> >
> >It's been a while since I've worked with applets, but if I understand you
> >correctly, the solution is simple.
> >
> >You have an HTML page with an embedded applet.  You want the applet to
tell
> >the browser to display a new HTML page which happens to be the result of
> >calling a servlet.  Correct?
> >
> >If so, simply use the Applet API to get a reference to its context and
tell
> >the browser to call the servlet, providing the appropriate URL.  The
> >browser
> >will do everything from there:  open a connection, execute the servlet,
> >retrieve the output, and finally display the result.
> >
> >Peace,
> >Dj
> >
> >David Harkness
> >Tech Lead, Web Group
> >T o p i c a , i n c .
> >[EMAIL PROTECTED]
> >
> >-----Original Message-----
> >From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> >Sent: Wednesday, June 07, 2000 9:47 PM
> >To: [EMAIL PROTECTED]
> >Subject: TECH: Servlets : How to do this
> >
> >
> >
> >Dear friends
> >
> >I have an applet which is talking to a servlet. The applet has following
> >
> >piece of code
> >
> >servletConnection.setDoInput(true);
> >servletConnection.setDoOutput(true);
> >
> >Then there is a method called
> >readServletResponse(servletConnection);          which reads the response
from
> >the
> >servlet.
> >
> >If I comment out the the call to this methos the communication does not
> >take
> >place So I have to cal this method. Why is this?
> >
> >However my original problem is that after I send the data to the servlet
> >.
> >the servlet authenticates the user and dynamically generates a new HTML
> >page
> >and writes it to the o/p stream.  I was expecting the HTML page to be
> >displayed. In normal circumstances the data is sent to the browser which
> >
> >knows how to parse this data.
> >
> >But in my case this o/p stream is connected to the applet therefore the
> >applet receives this data and does not know what to do with it.
> >
> >In short in applet-servlet scenario how do I load a new HTML page on the
> >
> >users browser?
> >
> >Any help?
> >
> >Nitin
> >
> >Amit Karmakar
> >List Administrator
> >To post a message: [EMAIL PROTECTED]
> >You can unsubscribe from this list at any time by sending a blank message
> >to [EMAIL PROTECTED] or
> >Visit http://www.topica.com/lists/Pune-Java
> >___________________________________________________________
> >T O P I C A  The Email You Want. http://www.topica.com/t/16
> >Newsletters, Tips and Discussions on Your Favorite Topics
> >
>
> ________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to