Javascript form post using a JSP page

Hello everyone.  

I'm stumped.  I'm sending a login and encrypted password from an ASP.NET page to a JSP page via the querystring.  I check the querystring for the data, and then decrypt the password and fill in the form boxes with the info.

After I do this, I want to auto-post the form so it logs the user in automatically.  I'm having trouble trying to get javascript to post the form.

The error I'm getting is:  'document.forms.formTest' is null or not an object

Appreciate any help.
<%
	String strDecryptedPassword = "";
	String strLogin = "";
	try
	{
		if(request.getParameter("login") != "" && request.getParameter("password") != "")
		{
			strLogin = request.getParameter("login");
			strDecryptedPassword = DecryptPassword(request.getParameter("password"));
			%>
			<script language="javascript">
				document.forms['formTest'].submit();
	                </script>
			<%
		}
	}
	catch(Exception e)
	{
		strLogin = "";
		strDecryptedPassword = "";
	}
%>
 
<FORM name="formTest" METHOD=POST ACTION="j_security_check">
<input type="text" size="20" name="j_username" id="j_username" class="field" value='<%=strLogin%>'/>
<input type="password" size="20" name="j_password" class="field" value='<%=strDecryptedPassword%>'/>
<input type="submit" name="login" value="Login" class="formButton"/></div>
</form>

Open in new window

evertithAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bobbit31Commented:
Hello evertith,

try:

<FORM ID="formTest" METHOD=POST ACTION="j_security_check">

Regards,

bobbit31
0
contactkarthiCommented:
if(request.getParameter("login") != "" && request.getParameter("password") != "")

should be replaced as

if(!request.getParameter("login").equlas("") && !request.getParameter("password").equlas(""))
0
bobbit31Commented:
nevermind my first post...

i think the problem is that your form isn't rendered at the time which the jsp code is run... what happens if you put the jsp stuff AFTER the form declaration?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

contactkarthiCommented:
document.forms['formTest'].submit();

should be

 document.formTest.submit();
0
contactkarthiCommented:
oops

just having submit in javascript will not submit the page

i will ask you to call a script function on page load and check if the values are there. if it is there then submit it

something like below

function changeVal() {

       if(<%=(!request.getParameter("login").equlas("") && !request.getParameter("password").equlas(""));>)
{
document.formTest.submit();
}


}


<body onload = "checkVal()" >
0
contactkarthiCommented:
function name was wrong

here is the correct one

function checkVal() { 
       if(<%=(!request.getParameter("login").equlas("") && !request.getParameter("password").equlas(""));>)
{
document.formTest.submit();
} 

} 

<body onload = "checkVal()" >

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
evertithAuthor Commented:
Appreciate the quick responses!  Worked like a charm.  I altered your code just a bit to fit my needs, but the logic was dead on.  Appreciate the push over the hump!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.