beans in jsp

hi ,

i am working on beans and jsp.Its a simple application. Thers is an html form (GetName1.html) which sends user data(name , age and email) to a jsp file(SaveName1.jsp) . Then SaveName1.jsp uses the bean and displays the data.
All my files (html,bean and jsp) are stored in the same package called FileExchange. When i am entering data in the html form and on hitting submit, its giving error.Its unable to  recognize the bean in the jsp file.


This is my html form:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head><title>JSP Page</title></head>
<body>
<form method=post action="SaveName1.jsp">
what is your name? <INPUT type=Text name=username size=20>
what is your email address ?<input type=Text name='email' size='20'><BR>
what is your age ?<input type=Text name='age' size='4'><BR>

<p><Input type=SUBMIT>
</form>
</body>
</html>

----------------------------------

This is my bean :( the bean takes the data from the user input:
package FileExchange;

/**
 *
 * @author  Byron
 */
public class UserData
{

    String username;
    String email;
    int age;
   
    public void setUsername(String value)
    {
        username = value;
    }
    /** Creates a new instance of UserData */
    public void setEmail(String value)
    {
        email = value;
    }
   
    public void setAge(int value)
    {
        age = value;
    }
   
    public String getUsername()
    {
        return username;
    }
   
    public String getEmail()
    {
        return email;
    }
       
    public int getAge()
    {
        return age;
    }
   
}
   
--------------------------------
This is my jsp which uses above bean:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<jsp:useBean id="user" class="UserData" scope="session"/>
<jsp:setProperty name="user" property="*"/>
<html>
<body>
<a href="NextPage1.jsp">continue</a>
<%-- <jsp:useBean id="beanInstanceName" scope="session" class="beanPackage.BeanClassName" /> --%>
<%-- <jsp:getProperty name="beanInstanceName"  property="propertyName" /> --%>

</body>
</html>

---------------------------------------------

The "UserData" bean in the above jsp  is not been recognized .








any help greatly appreciated.

thanks,
j

LVL 10
jaggernatAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
you need to include the package name:

<jsp:useBean id="user" class="FileExchange.UserData" scope="session"/>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jaggernatAuthor Commented:
i did..but now it says "package "FileExchange" does not exist.

0
objectsCommented:
where is UserData.class?
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

jaggernatAuthor Commented:
its in the same package "FileExchange"

all programs are in the same package "FileExchange"
0
CodingExpertsCommented:
Where are your class files??. They need to be either in WEB-INF/classes or should be included in the classpath.

<CE>
0
objectsCommented:
sorry I meant in what directory is the file in?
0
objectsCommented:
unless they are in a jar it needs to be in

<webapp>/WEB-INF/class/FileExchange
0
jaggernatAuthor Commented:
ok ..this is my mounted directory
c:\doc\byron\desktop\courses\htmljava\javapr\FileExchange

in the above directory , i have all the files.

although , in FileExchange directory , there is Web-inf\classes  and web-inf\lib






0
objectsCommented:
sounds like you need to create the following directory and put UserData.class in there:

c:\doc\byron\desktop\courses\htmljava\javapr\FileExchange\Web-inf\classes\FileExchange
0
jaggernatAuthor Commented:
ok ..just the userdata.class or all the programs
0
objectsCommented:
just UserData.class
0
jaggernatAuthor Commented:
it still says FileExchange cannot be found

sorry ,,i just gave some wrong infor above by mistake .

this is my mounted directory

1) c:\doc\byron\desktop\courses\htmljava\javapr  and NOT  c:\doc\byron\desktop\courses\htmljava\javapr\FileExchange

2) In c:\doc\byron\desktop\courses\htmljava\javapr,,  i have created a web-module such that now after creating web-module it displays :c:\doc\byron\desktop\courses\htmljava\javapr : /WEB-INF/classes

3) I have created a directory called FileExchange UNDER  c:\doc\byron\desktop\courses\htmljava\javapr
and stored all my files in it .They are : GetName1.html, SaveName.jsp,NextPage1.jsp and UserData.java

I am getting error : Package FileExchange  does not exist.




thanks
0
scommissoCommented:
Remember, when you're creating Java packages, each package level is equivalent to a directory.

For example:

FileExchange.UserData;
is equivalent to:
FileExchange/UserData.class

or...

FileExchange.*
is equivalent to:
FileExchange/*.*

So, when you're putting together your /classes directory, keep this in mind. As the above user stated, it sounds like your directory structure is a bit messed up.
0
jaggernatAuthor Commented:
yes ,,it was a little bit messed up..

but now i have got a good hold of it..

what i am confused about is my" html" and "jsp" files are in same directory/package called FileExchange under    c:\doc\byron\desktop\courses\htmljava\javapr

I have placed the bean file (class file ) under c:\doc\byron\desktop\courses\htmljava\javapr\WEB-INF\classes\FileExchange\UserData

now, When i execute html file from netbeans3.6 ,,it goes to SavaName1.jsp but gives package FileExchange does not exist.
-------------------------
this is my jsp:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<jsp:useBean id="user" class="FileExchange.UserData" scope="session"/>
<jsp:setProperty name="user" property="*"/>
<html>
<body>
<a href="NextPage1.jsp">continue</a>
<%-- <jsp:useBean id="beanInstanceName" scope="session" class="beanPackage.BeanClassName" /> --%>
<%-- <jsp:getProperty name="beanInstanceName"  property="propertyName" /> --%>

</body>
</html>


 
0
objectsCommented:
from what you've said your class file should be in:

c:\doc\byron\desktop\courses\htmljava\javapr\WEB-INF\classes\FileExchange\UserData.class


is this the case?

and make sure you restart tomcat

0
jaggernatAuthor Commented:
yes,,UserData.class  is in
c:\doc\byron\desktop\courses\htmljava\javapr\WEB-INF\classes\FileExchange

All other files are stored in
c:\doc\byron\desktop\courses\htmljava\javapr\FileExchange



0
kupra1Commented:
first do an import of your bean in your jsp class.
something like this:
<%@ page import="FileExchange.UserData" %>
and set the classpath to the folder in which your classes are.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.