?
Solved

submitting form with enter key in JSP

Posted on 2003-12-08
5
Medium Priority
?
1,124 Views
Last Modified: 2012-06-27
I want to do the same action as pressing the login button when a user clicks return/enter in the input box. When user clicks the login button - page is reloaded- and embedded java executes the code after 'if (strbtnSubmit != null) {' condition. Thanks

heres my code (it is a jsp page)

<%@page import="utilities.*"%>


<head>


<%

String strbtnSubmit = request.getParameter("btnSubmit");

// submit - refresh the page
try{
if (strbtnSubmit != null) {
        String pass1 = request.getParameter("pass");
        utilities.Password password = new utilities.Password();
        HttpSession session1 = request.getSession(true);

            if (password.checkPassword(pass1)) {
           
               
                session1.setAttribute("matchingPassword", request.getParameter("pass"));
                session1.setAttribute("sessionID", session1.getId());
                String redirectURL = "/im/menu/Control.jsp";
                response.sendRedirect(redirectURL);
             } else { session1.invalidate(); }
          }

} catch (Exception exception) {throw exception;}
%>


</script>

</head>

<body leftmargin="0" topmargin="30" marginwidth="0" marginheight="0"></head>
<body><font face="verdana">

<table bgcolor="#FFFFCC" width="100%" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr>
    <td width="34" rowspan="3" valign="top" bgcolor="#FFFFCC"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td width="100%" rowspan="4" valign="top"><form name="loginform" action="/im/forms/Login.jsp">
        <table bgcolor="#000000" border="0">
          <!--DWLayoutTable-->
          <tr>
            <td width="223" rowspan="3"> <img src="/im/menu/im.jpg" width="217" height="148">
            </td>
            <td width="90" rowspan="3"> <font color="silver">Password:</font>
            </td>
            <td height="63" colspan="2" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
            <td width="18" rowspan="3">&nbsp;&nbsp;&nbsp;</td>
          </tr>
          <tr>
            <td height="33" colspan="2" valign="top"><input style="color:black; background-color:grey; border-width: 1px; border-color:black" type="password" name="pass" size="15"></td>
          </tr>
          <tr>
            <td width="39" height="50" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
            <td width="50" valign="top"><input style="color:black; background-color:grey; border-width: 1px; border-color:black" align="right" type="submit" value="Login" name="btnSubmit"></td>
          </tr>
          <tr>
            <td height="26" align="right"><!--DWLayoutEmptyCell-->&nbsp; </td>
            <td colspan="4" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
          </tr>
        </table>
      </form></td>
    <td width="238" height="35">&nbsp;</td>
    <td width="112">&nbsp;</td>
  </tr>
  <tr>
    <td height="26" valign="top">entry portal | <font color="orange"><strong>IM</strong></font></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td height="106"></td>
    <td></td>
  </tr>
  <tr>
    <td height="15"></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td height="0"></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td height="1"><img src="/im/menu/spacer.gif" alt="" width="34" height="1"></td>
    <td></td>
    <td><img src="/im/menu/spacer.gif" alt="" width="238" height="1"></td>
    <td><img src="/im/menu/spacer.gif" alt="" width="112" height="1"></td>
  </tr>
</table>
</body>


</html>

0
Comment
Question by:cratnayake_pa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 

Author Comment

by:cratnayake_pa
ID: 9901754
btw...

<td height="33" colspan="2" valign="top"><input style="color:black; background-color:grey; border-width: 1px; border-color:black" type="password" name="pass" size="15"></td>


is the input box which the user enters their password- upon enter in this box - the form is submitted same as pressing the login button underneath

at present moment.. when enter is pressed after entering correct password.. the page just reloads with

http://localhost:8081/im/forms/Login.jsp?pass=

in the URL (IE 6.0)
0
 

Author Comment

by:cratnayake_pa
ID: 9901755
or
http://localhost:8081/im/forms/Login.jsp?pass=mypassowrd

(where mypassword varies depending on what you have entered into the input box)
0
 
LVL 10

Expert Comment

by:D_M_D
ID: 9903732
You can use javaScript to capture the enter keystroke...

<script language="JavaScript">
if (document.all || document.layers){
      document.onkeypress=pressed; // IE4+ & NS4+
      
}
function pressed(e) {
     var Val='';
     if (document.layers){
         Val='' + e.which;
     }else{
         Val = window.event.keyCode;
     }
     if (Val == 13){
        document.YourFormName.submit();
     }
}
</script>

Just add your Form Name above...

Hope this helps...

--------
D_M_D
0
 
LVL 6

Accepted Solution

by:
DoppyNL earned 600 total points
ID: 9903989
I would strongly recommend using the post-method for forms that contain passwords.
That way the password entered won't be in the URL wich is **MUCH MORE SECURE**
0
 
LVL 6

Expert Comment

by:jwenting
ID: 9911593
If your HTML form has one or more submit buttons, the enter key will trigger the first of those automatically (unless you remap the enter key to do something else).
0

Featured Post

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
The viewer will learn how to count occurrences of each item in an array.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question