Solved

jsp:setproperty not working

Posted on 2006-07-07
5
642 Views
Last Modified: 2010-07-27
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;
      }
0
Comment
Question by:GrnEggsAndHam
  • 4
5 Comments
 
LVL 8

Accepted Solution

by:
thomas908 earned 500 total points
ID: 17056787
put your
 <jsp:setProperty name="user" property="*"/>
outside your
<jsp:useBean .../>
0
 
LVL 8

Expert Comment

by:thomas908
ID: 17056789
<jsp:useBean id="user" scope="session" class="org.stuff.domain.User"></jsp:useBean>
 <jsp:setProperty name="user" property="*"/>
0
 
LVL 8

Expert Comment

by:thomas908
ID: 17056794
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
0
 
LVL 8

Expert Comment

by:thomas908
ID: 17056805
0
 
LVL 2

Expert Comment

by:vikrant4u2
ID: 17056843
remove scope="session" and it will work

regards,
vikrant
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet concurrency 13 111
authenticate preemptively soap ui option 3 158
Books that can get me started on JAVA 2 107
going to wrong jsp page 2 34
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
Use Windows Task Scheduler to print a Word document weekly so your printer ink won't dry out.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question