Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 366
  • Last Modified:

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

0
jaggernat
Asked:
jaggernat
1 Solution
 
objectsCommented:
you need to include the package name:

<jsp:useBean id="user" class="FileExchange.UserData" scope="session"/>
0
 
jaggernatAuthor Commented:
i did..but now it says "package "FileExchange" does not exist.

0
 
objectsCommented:
where is UserData.class?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now