views:

33

answers:

1

Hi everyone, I'm in a bit of a dilemma on how to connect the above mentioned three technologies. I'm still a student so please bare with me on this as I try to explain my problem.

For an assignment I have to create a simple form that uses JSP for the view with the Model and the controller being Servlets, the communication needs to be done using JavaBeans.

I've created a JSP powered form to accept a user name and a password which needs to be authenticated for the user to be able to post & view messages in the Forum I've used the following code to read the JSP textbox:

<%@page import="forum.beans.*" %>

<html>
  <head>
    <title>Login - Meassage Bord</title>
        <%
                String uname = request.getParameter("uname");
            String pass = request.getParameter("pass");

%>
  </head>
  <body bgcolor="LightSteelBlue">
    <font face="Calibri, Centuary Gothic, Times New Roaman">
        <table border="0" align="center">
          <form method="post" action="servlet\Controller">

                <tr>
                    <td>Username: *</td>
                    <td><input name="uesername" value="<%=uname%>" type="text" /></td>
                </tr>

                <tr>
                    <td>Password: *</td>
                    <td><input name="password" value="<%=pass%>" type="password" /></td>
                </tr>
                <tr>

                    <td align="center"> <br /><br /><input type="submit" value="Login" /></td>

                    <td align="center"> <br /><br /><input type="reset" value="Clear" /></td>
                </tr>

            </form>
        </table>

    </font>
  </body>
</html>

My questions are,

instead of what I've used should I use

<%request.getParameter("uesername");%>

secondly the how can transfer these values in to JSP tags??

Thank you very much or your time guys

+1  A: 

instead of what I've used should I use

<%request.getParameter("uesername");%>

You should be doing this in the doPost() method of the controller servlet which is listening on the form's action URL. Noted should be that in case of a good JSP/Servlet model/view/controller design, the JSP should not contain any scriptlet line. Keep this in mind. See also this topic for several hints.

secondly the how can transfer these values in to JSP tags?

You can retain them by ${param} in EL. It basically refers to a Map<String, String> where the parameter name is the key.

<input name="username" vaule="${param.username}">

Noted should be that this is sensitive to XSS attacks. You might earn extra points if you figure how to solve this ;)


Another unrelated comment: the HTML <font> tag is deprecated since 1998. I am not sure where you've learnt about it, but those sources are far outdated. You sould be using CSS to give style to the HTML document.

BalusC
Hi Balus, thanks for the post, the lecturer has specifically asked us not to spend time on "gold plating" the system that's why I'm using the stone age methods shown here. On the note of the question above after a bit of deliberation I've taken a different approach which seems to be going well, I will post if I have any more questions.
Kushan