开发者

JSP JavaBean and Servlets?

开发者 https://www.devze.com 2023-01-17 22:48 出处:网络
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 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\Controll开发者_StackOverflow社区er">

                <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??


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消