On Thu, 27 Jun 2002 09:54:15 +1000, Gare, Tref <[EMAIL PROTECTED]> wrote:

>You might need to submit the code for me to be able to help more
>effectively,
>but it seems that you're javascript may not be doing all of it's job.
>
>If I were trying to achieve the same thing I'd do something like the
>following.  It should only ever get around to submitting if the
>checkSubmit() function returns true.
>
>
>
><html>
><head>
>
><script language="javascript">
>        //function to confirm that username and password fields have been
>populated.
>        //It could use further validation to check length, type of content
>etc etc
>        function checkSubmit(){
>                if(document.blahForm.username.value == "" ||
>document.blahForm.password.value==""){
>                        alert("must fill in the username and password fields
>before submitting");
>                        return false;
>                }else{
>                        return true;
>                }
>        }
>
>
></script>
></head>
><body>
>
><form name="blahForm" action="blah.jsp" method="POST" onsubmit="return
>checkSubmit()">
><input type="text" name="username" value="">
><input type="password" name="password" value="">
><input type="submit" name="submit" value="submit form">
></form>
>
></body>
></html>
>
>> -----Original Message-----
>> From: Rajkumar, Haripriya (Haripriya) [SMTP:[EMAIL PROTECTED]]
>> Sent: Thursday,27 June 2002 2:36
>> To:   [EMAIL PROTECTED]
>> Subject:      HTML Form submit action and JSP interaction...
>>
>> Hi,
>>
>> I am writing a simple login validation pgm. I have a HTML file which has
>> the
>>
>> login form and it action points to a JSP page that needs to be displayed
>> ONLY AFTER the
>> user has been successfully validated.
>>
>> Also, I have a JavaScript file that holds function to check for empty
>> fields
>> in the form and
>> sends an alert.
>>
>> Basically
>>
>> 1. If empty fields are present the JavaScript, alert needs to be called
>> and
>> the HTML form page
>> should still be visible.
>>
>> 2. If userId and password are entered but are not valid, then the JSP page
>> that prints out the
>> error message has to be displayed.
>>
>>
>> Here is what happens. When the HTML form is called in the browser, and
>> userid or password is not entered
>> then the alert is displayed properly. After entering the userid and
>> password, it goes to the JSP
>> page properly.
>>
>> BUT when, I use the browser's BACK button, and go to the HTML form page,
>> and
>> if the password field is not
>> present and try to hit submit button, The Alert message is displayed AS
>> WELL
>> AS the JSP page too, seems
>> like the SUBMIT action is getting called. How do I fix this, so that even
>> if
>> teh user, hits the
>> BACK button and tries to login giving empty fields, ONLY the alert has to
>> be
>> displayed.
>>
>> Any pointers???
>> Thanks
>> PHR
>>
>> ==========================================================================
>> =
>> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
>> JSP-INTEREST".
>> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
>> DIGEST".
>> Some relevant FAQs on JSP/Servlets can be found at:
>>
>>  http://archives.java.sun.com/jsp-interest.html
>>  http://java.sun.com/products/jsp/faq.html
>>  http://www.esperanto.org.nz/jsp/jspfaq.jsp
>>  http://www.jguru.com/faq/index.jsp
>>  http://www.jspinsider.com
>
> ==========================================================================
>To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
>For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
>Some relevant FAQs on JSP/Servlets can be found at:
>
> http://archives.java.sun.com/jsp-interest.html
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.jsp
> http://www.jguru.com/faq/index.jsp

The checkSubmit() function will work for validation purposes, but will not resolve the 
Back button problem.

My suggestion (the way we typically handle this) is to force the client to the login 
page only if they aren't already logged in. Your JSP page becomes the 'frontdoor' and 
looks to see if there is a cookie cred that indicates authorization. IF they haven't 
been authenticated (logged in) the JSP page redirects them to the login screen which 
writes the cookie) and passes the JSP URL in the request string.

Your login screen must also check for the cookie. If you hit back after logging in and 
there is a cookie, it automatically redirects to the initial 'frontdoor' JSP page and 
not the login screen.

It is more an architectural problem than a code problem.

Ben Cramer
iPath Solutions

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to