request.getAttribute return null...

I am beginner to servlets. I am writing a small application.

I have a register servlets which get username and password.

PrintWriter pw = response.getWriter();

pw.println( "<html>" );

pw.println( "<head>" );

pw.println( "</head>" );

pw.println( "<body>" );

pw.println( "<form name='frm1' method='POST' action=/HelloWorld/CreateLoginUser>" );

pw.println("Username : ");

pw.println( "<input type=\"text\" name='uname'/>

" );

pw.println("Password : ");

pw.println( "<input type=\"text\" name='pwd' />

" );

pw.println( "<input type='submit' name='submitbutton' value='Create'/>" );

pw.println( "</form>");

pw.println( "</body>" );

pw.println( "</html>" );

Next I have the CreateLoginuser servlets

String username = (String)request.getAttribute("uname");

String password = (String)request.getAttribute("pwd");

try {

boolean isExist = UserList.isUserExist(username);

if(isExist){

//inform the client

return;

}

//create the user

} catch (SQLException e) {

e.printStackTrace();

}

While I debug in eclipse i get null in request.getAttribute for username and password. pls help me to get rid of the problem

[1369 byte] By [hari3091a] at [2007-11-26 15:11:38]
# 1

>String username = (String)request.getAttribute("uname");

>String password = (String)request.getAttribute("pwd");

Wrong Usage as per the context you are refering to.

For further info refer to API

http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletRequest.html#getAttribute(java.lang.String)

in the present context make use of

String username = request.getParameter("uname");

String password = request.getParameter("pwd");

Hope tht helps...

REGARDS,

RaHuL

RahulSharnaa at 2007-7-8 9:02:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Yes! Thanks Rahul. Now I am safe.
hari3091a at 2007-7-8 9:02:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...