0

Am new to JSP and Servlets so please bear with me for my simple question

I have designed a login page (Login.jsp) which validates the credentials entered by the user in the database and if the credentials matches, then am displaying a new jsp (loginsuccess.jsp).

However, when the user enters wrong credentials am redirecting to the Login.jsp and am displaying the error message "Please check your username or password). But this message is displayed after the Submit button in the login page.

Now, i want this error message to be displayed just before the Submit button and after the Password field (example: as it is done in the Gmail login page)

Currently am using the following code to display the error message

<%
String error=request.getParameter("error");
if(error==null || error=="null"){
 error="";
}
%>

the parameter "error" will be set in the loginsevlet upon validation.

But this message is currently displaying after the Submit button. Am displaying the Login fields (username, password and submit button) using a table as separate rows. With the current design (table) will it be possible to insert dynamically the error message as a new table row before the Submit button table row ?

Any pointers is much appreciated

Jack Clouseau
  • 81
  • 1
  • 11
  • The code you posted doesn't display anything. It initializes a local variable named error from a request parameter, that's all. Please read http://stackoverflow.com/questions/2188706/how-to-avoid-using-scriptlets-in-my-jsp-page – JB Nizet May 01 '14 at 07:47
  • Hi, thanks for your quick reply. Yes, i forgot to put the code that displays the error message in my post. But am actually doing it. However, i figured out how to display it. Am using the table row with the following code
    <%=error%>
    . Many thanks for your quick reply
    – Jack Clouseau May 01 '14 at 07:56
  • Edit your question, and make it answerable. There is no way to tell you how to fix the problem if you just show the code displaying the error. We're not extra-lucid wizards, so we don't know where the password field and the submit buttons are. – JB Nizet May 01 '14 at 07:58

1 Answers1

1

You are expecting answer i think so, don't ask the code like this, first google it and find the code, if you had any bug in that code, then you can use the stackoverflow this is not the forum, and what you expected is below.

inside HTML head place this code:

<%
    String error=request.getParameter("error");
    if(error==null || error=="null") {
        error="";
    }
%>

inside HTML body place this code:

<from method="post" action="redirect.jsp">
    <table>
        <tr>
            <td>
                <input type="text" id="name" />
            </td>
        </tr>
        <tr>
            <td>
                <input type="password" id="pass" />
            </td>
        </tr>
        <tr>
            <td>
                <%= error %>
            </td>
        </tr>
        <tr>
            <td>
                <input type="submit" value="Login" />
            </td>
        </tr>
    </table>
</from>

above code will works fine.

Community
  • 1
  • 1
Selva
  • 546
  • 5
  • 12
  • 34