File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes doubts in Login page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "doubts in Login page " Watch "doubts in Login page " New topic
Author

doubts in Login page

pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 339
Hi
This is a jsp login page .I have some doubts/problems in highlighted code in this page.Please anybody give solutions to my questions

Question 1.In input type element ,what is the use of id and value attributes?ex. <input type="text" name="user_id" id="user_id" value="" />

Question 2.What is the use of below 2 lines in this page?Why only first one is not sufficient and if sufficient then in what situation or condition we use 2nd line also?
<input type ="submit" name="submit" id="submit" value="Change Password" />
<input type="hidden" name="action_chngpswd" id="action_chngpswd" value="hrms_change_pswd_submit"/>
</td></tr>

Question 3.What is .. in this line?why we can not use complete path or in what condition/situation it is used?
"><%@include file="../jsp/hrms_footer.jsp"%></td>








<html>
<head><title>www.hrsolutions.com/User Login</title>
<link rel="stylesheet" href="../css/mystyle.css" type="text/css" />
</head>
<body>
<form name = "form1" method="post">
<table width="900" align=center>
<tr>
<td colspan="2"><%@ include file="\jsp\hrms_header.jsp" %></td>
</tr>
<tr >
<td colspan="2">
<table border ="0" align="center" >
<tr><td>User Id</td>
<td align="center" ><input type ="text" name="user_id" id="user_id" value="" /></td></tr>
<tr><td>User Name</td>
<td align="center" ><input type ="text" name="user_name" id="user_name" value="" /></td></tr>
<tr><td>Password</td>
<td align="center" ><input type ="password" name="user_pswd" id="user_pswd" value="" /></td></tr>
<tr><td colspan="2" align="center" ><input type ="submit" name="submit" id="submit" value="Submit" />
<input type="hidden" name="action_submit" id="action_submit" value="hrms_user_login_submit"/>
</td></tr>
<tr><td colspan="2" align="center">
<input type ="submit" name="submit" id="submit" value="Change Password" />
<input type="hidden" name="action_chngpswd" id="action_chngpswd" value="hrms_change_pswd_submit"/>
</td></tr>
<%
String msg = (String)session.getAttribute("lErrorMsg");
if ( msg != null && msg.length() > 0 ){
%>
<tr>
<td colspan="2" align="center">
<%out.println("<div class=boldred>"+msg+"</div>"); %>
</td>
</tr>
<%}%>
</table>
</td></tr>
<tr>
<td colspan="2"><%@include file="../jsp/hrms_footer.jsp"%></td></tr>
</table>
</form></body></html>


SCJP 5.0(75%), SCWCD 5.0(88%)
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1

Hi Pradeep,

The 'id' is used so that the particular element can be accessed usind script eg. JavaScript. Something like

var element = document.getElementById("id");

For text fields the value attribute specifies its content.

An input type 'submit' is a Submit button which can be used to submit the <form>. And a 'hidden' element is like a test field with the difference that it wont get displayed on the page. It is used to store values within the form as well as to maintain session information.

Of course absolute paths can be used. There are two ways of specifying path from a page. 1) Absolute path and 2) Relative path. In the example snippet a relative path has been used (relative to the current page). The advantage of a relative path is that the page/application is not bound to the exact location it is on the system.

Hope I have been able to clear some of your doubts.

Cheers,
Raj.
Sidharth Pallai
Ranch Hand

Joined: Apr 21, 2008
Posts: 134

Hello pradeep

The use of id is specifically for use with javascript/CSS to change/trigger some actions based on some event upon submit like onmouseover,onclick,etc etc. The javascript function can make use of id's by fetching the input element to process like document.form.getElementById(id) and trigger action based on event occured with the submit button.
Hidden input fields is a way to track sessions,they are not visible in browser but worth having it for specific purposes to transfer data.
The use @include is directive include element in JSP used to include the file on compilation unlike <jsp:include> which does in runtime.It just includes the source on complile


Thanks & Regards
Sidharth Pallai
pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 339
Hi thanks to you all
But 2nd question is not solved,it is unsolved .Please see the complete code of this login and then tell me what is the use of this hidden submit here.If we click the submit button then what happened.U know hidden button is not seen in the login page.?if we click the submit button then hidden button automatically clicked.Please read the complete code .

And also in first question if I enter the value in text field then what will be the accessed value by getParameter: "" (empty string) or entered text.

[ May 14, 2008: Message edited by: pradeep singh ]
[ May 14, 2008: Message edited by: pradeep singh ]
Sidharth Pallai
Ranch Hand

Joined: Apr 21, 2008
Posts: 134

Hi Pradeep
Regarding your 2nd problem with hidden input seems no issues.You seem to bit confused with hidden input.Firstly, i would like to say that hidden inputs are not submit button what you have said, but they are invisible text field so they there is no issue of automatic click of the hidden input.They are generally used to pass hidden values (Not entered by user) as request parameters like if you wish to pass login time/date to some action/servlet, then you substitute such information into value attribute of hidden field.Like

Or you can calculate the date/time within a javascript function and substitute to the hidden value like
In this case you need to add an id attribute to your hidden field.You can fetch the time as request.getParameter(LastLoginTime) for any use in action.
And regarding your first problem ,whatever value has been substituted to the value attribute of submit input you will be getting the same value.
I hope you seem to be now confirmed about this issue.Anyway i would be waiting for your reply with pleasure. :thumb:
pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 339
Hi
Thanks Sidharth Pallai
I am satisfied with your answer.But still have a little doubt in first question is
<input type="text" name="user_id" id="user_id" value="" />
IN this why we have used value="".


A new question is in this login jsp we have not provided action,then where this form data will go?
I think the form data will go to that page from which control is forwarded to this login page .
Sidharth Pallai
Ranch Hand

Joined: Apr 21, 2008
Posts: 134

The use of value="" clearly denotes a default value to the input field.Like if you wish to have a default value say "hi" you can just do it with value="hi" but its not mandatory but depends upon circumstances.Apart from this your form seem to have no action,i have no idea about your experiments with form elements,well you can try this out and watch what exactly what happens to a action-less form upon submission.Basically all the input values exist in request scope of HttpServletRequest till it expires.
pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 339
Hi Thanks!
In action less form ,the request object goes to that from which it is called.I tested it .

Please clear me, there are two submit button and two hidden field .If we press the Submit button,then are both hidden fields will be in request object or only one ? Please read it clarefully.Book says that it is kind of some mapping and only one hidden field in this code goes to request object.

With submit button having value "Submit" ,hidden field thats' name "acton_submit" and value ="hrms_user_login_submit" goes to the request object

and with submit button having value "Change Password " ,hidden field that's name "action_chngpswd" and value="hrms_change_pswd_submit" goes to the request object.This is the way it is working But why?



<html>
<head><title>www.hrsolutions.com/User Login</title>
<link rel="stylesheet" href="../css/mystyle.css" type="text/css" />
</head>
<body>
<form name = "form1" method="post">
<table width="900" align=center>
<tr>
<td colspan="2"><%@ include file="\jsp\hrms_header.jsp" %></td>
</tr>
<tr >
<td colspan="2">
<table border ="0" align="center" >
<tr><td>User Id</td>
<td align="center" ><input type ="text" name="user_id" id="user_id" value="" /></td></tr>
<tr><td>User Name</td>
<td align="center" ><input type ="text" name="user_name" id="user_name" value="" /></td></tr>
<tr><td>Password</td>
<td align="center" ><input type ="password" name="user_pswd" id="user_pswd" value="" /></td></tr>




<tr><td colspan="2" align="center" ><input type ="submit" name="submit" id="submit" value="Submit" />
<input type="hidden" name="action_submit" id="action_submit" value="hrms_user_login_submit"/>




</td></tr>
<tr><td colspan="2" align="center">
<input type ="submit" name="submit" id="submit" value="Change Password" />
<input type="hidden" name="action_chngpswd" id="action_chngpswd" value="hrms_change_pswd_submit"/> </td></tr>
<%




String msg = (String)session.getAttribute("lErrorMsg");
if ( msg != null && msg.length() > 0 ){
%>
<tr>
<td colspan="2" align="center">
<% out.println("<div class=boldred>"+msg+"</div>"); %>
</td>
</tr>
<% } %>
</table>
</td></tr>
<tr>
<td colspan="2"><%@include file="../jsp/hrms_footer.jsp"%></td> </tr>
</table>
</form></body></html>


[ May 15, 2008: Message edited by: pradeep singh ]

[ May 15, 2008: Message edited by: pradeep singh ]

[ May 15, 2008: Message edited by: pradeep singh ]
[ May 15, 2008: Message edited by: pradeep singh ]
Sidharth Pallai
Ranch Hand

Joined: Apr 21, 2008
Posts: 134

Cheer up dude, You are still confused. I think you need to brush up the basics or should practise well before you post such issues. Well dont worry,you can easily go through it.Once again i would say that if a form contains some input elements(submit,hidden,select,dropdown....) they all get submitted to server and each get registered with HttpServletRequest.Its clearly visible when you send the form using "method=get" , the URL quesry string will clear your doubt.
John Pearson
Ranch Hand

Joined: Oct 19, 2007
Posts: 51
You mentioned a book that says it is some kind of mapping. What book? And what happens when you test it? Does it really submit just one of the hidden field name/value pairs, or does it submit both of them?
pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 339
Hi Thanks
Yes i was confused .Now all clouds of confusion are over now.Thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubts in Login page