Link to home
Start Free TrialLog in
Avatar of GrnEggsAndHam
GrnEggsAndHam

asked on

jsp:setproperty not working

having troubling getting the jsp:setProperty to work.  here is my jsp page and bean...can anyone tell me why this is not working?  If i explicitly set the value="something" then setProperty works, but I need to capture the html input...thanks in advance!

here's my jsp page called login.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ page session="true" %>
   
        <jsp:useBean id="user" scope="session" class="org.stuff.domain.User">
                  <jsp:setProperty name="user" property="*"/>
       </jsp:useBean>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

username: <%= user.getUsername() %>

<br/>
<form action="login.jsp" method="post">

Login id:
<input type="text" name="username" size="10"/>
<br/>
Passwd:
<input type="password" name="password" size="10"/>
<br/>
 <input type="submit" name="submit"/>
</form>
</body>
</html>


And here is my bean:

package org.stuff.domain;

public class User implements java.io.Serializable {

      private String username;
      private String password;
      
      public User() {
      // TODO Auto-generated constructor stub
      }
      public String getPassword() {
            return password;
      }
      public void setPassword( String password ) {
            this.password = password;
      }
      public String getUsername() {
            return username;
      }
      public void setUsername( String username ) {
            this.username = username;
      }
ASKER CERTIFIED SOLUTION
Avatar of thomas908
thomas908

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thomas908
thomas908

<jsp:useBean id="user" scope="session" class="org.stuff.domain.User"></jsp:useBean>
 <jsp:setProperty name="user" property="*"/>
Body tags are only processed if <jsp:useBean> instantiates the Bean. If the Bean already exists and <jsp:useBean> locates it, the body tags have no effect.
Using

 <jsp:useBean id="user" scope="session" class="org.stuff.domain.User" />
 <jsp:setProperty name="user" property="*"/>

will set the property even if the bean already exists
remove scope="session" and it will work

regards,
vikrant