This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HFSJ book:Bean Example Page 357 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HFSJ book:Bean Example Page 357" Watch "HFSJ book:Bean Example Page 357" New topic

HFSJ book:Bean Example Page 357

Ranch Hand

Joined: Apr 17, 2005
Posts: 35
Hallo everyone,

this example is not working for me The rest of the examples in this chapter depend on this one so basically i am stock overhere

when i run the application i get no outupt and the parameter (user name) is passed in the URL. e.g. if i put "john" this is what i get in the address bar


any clue?

<form action="result.jsp">

name: <input type = "text" name="userName">
<input type="submit">



<jsp:useBean id="person" class="com.example.web.Person" >

<jsp:setProperty name="person" property="name"
value="<%=request.getParameter("userName")%>" />
java bean

package com.example.web;

public class Person {

private String name;

public void setName(String n)

public String getName()
return name;

package com.example.web;

import com.example.web.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

public class Test extends HttpServlet{

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{

Person p = new Person();

RequestDispatcher view= request.getRequestDispatcher("result.jsp");



<web-app xmlns=""




[ June 14, 2005: Message edited by: Jamed ]

[ June 14, 2005: Message edited by: Jamed ]

[ June 14, 2005: Message edited by: Jamed ]
[ June 14, 2005: Message edited by: Jamed ]
shri mon
Ranch Hand

Joined: Jan 11, 2005
Posts: 63
Where is the code for your servlet?

Can you please type that also.

One more thing.Try doing this,

<jsp:setProperty name="person" property="name"
value="john" />

is it printing then?

Ranch Hand

Joined: Apr 17, 2005
Posts: 35

i try what you have suggested but it's not working

i've posted my servlet at the the top

thanks in advance for you help
Radmika Arunachalam
Ranch Hand

Joined: Mar 29, 2004
Posts: 45
Change form action to ""

Also put <jsp:getProperty> in result.jsp to see whether it is set properly...

Ranch Hand

Joined: Apr 17, 2005
Posts: 35
i've changed the action to

it's still not working !

Sushma Sharma
Ranch Hand

Joined: Jun 02, 2005
Posts: 139
first thing, If your action in HTML form is result.jsp,so you don't need a servlet code. But, if you do want to use servlet code, then set the action to

second thing, in result.jsp, your setProperty tag would only execute if there is no person attribute in your page scope( as you have not specified the scope, it will default to page). If you specify the scope=request, the Container will search for the person attribute in the request scope.

third thing, you have not used the getProperty tag, that's why, your jsp is not displaying anything. use getProperty tag after your jsp:useBean tag ends.

hope this helps,

srinath anand
Ranch Hand

Joined: Nov 20, 2001
Posts: 30
Here is what you can do to get it working:

In result.jsp -

<jsp:useBean id="person" class="com.example.web.Person">
<jsp:setProperty name="person" property="name" value="<%=request.getParameter("userName")%>" />
<h1> The name of the person is: <jsp:getProperty name="person" property="name"/></h1>

In form.html -
<form action="">

Name: <input type = "text" name="userName">
<input type="submit">


Even if you say <form action="result.jsp"> it will work without any problems but since you have a mapping in the web.xml for it may be wise to use it.

Let me know if it works.


Ranch Hand

Joined: Apr 17, 2005
Posts: 35
Thank you very much srinath for you help

it did work with me with the solution provided by sushma

the problem was the i didn't use getProperty in my jsp and that's why it wasn't displaying anything when i tested it

but isn't this supposed to dipslay the name ?

thanks srinath and sushma for our hlep
[ June 17, 2005: Message edited by: Jamed ]
I agree. Here's the link:
subject: HFSJ book:Bean Example Page 357
Similar Threads
JSP - cannot resolve symbol
EL question
HFSJ EL e.g. page 371
Unable to getParameter in jsp
HFSJ book:Bean Example Page 345