aspose file tools*
The moose likes JSP and the fly likes how to use usebean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "how to use usebean" Watch "how to use usebean" New topic
Author

how to use usebean

girish chandran
Greenhorn

Joined: Dec 20, 2004
Posts: 2
Please verify the following program.I am passing username,email and age to a jsp page
"NextPage.jsp".I am using a bean program "UserData.java" to retrieve the value inside the jsp page.
I am using J2sdkee1.2.1, installed j2sdkee1.2.1 in D: drive. My doubt is where I have to keep the
class file for the bean UserData.java.I had kept the class file in the folder "d:\j2sdkee1.2.1\lib\classes".
Is it the right way to specify the class file?




GetName.html:
------------

<HTML>
<BODY>
<FORM METHOD=POST ACTION="NextPage.jsp">
What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20><BR>
What's your e-mail address? <INPUT TYPE=TEXT NAME=email SIZE=20><BR>
What's your age? <INPUT TYPE=TEXT NAME=age SIZE=4>
<P><INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>


NextPage.jsp:
------------

<jsp:useBean id="user" class="UserData" scope="session"/>
<HTML>
<BODY>
You entered<BR>
Name: <%= user.getUsername() %><BR>
Email: <%= user.getEmail() %><BR>
Age: <%= user.getAge() %><BR>
</BODY>
</HTML>


UserData.java:
-------------

public class UserData {
String username;
String email;
int age;

public void setUsername( String value )
{
username = value;
}

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; }
}




--------------------------------------------------------------------------------
Vikas
Ranch Hand

Joined: Dec 16, 2004
Posts: 63
Hi,

Which Application Server are you using??
girish chandran
Greenhorn

Joined: Dec 20, 2004
Posts: 2
I am using the J2EE server of j2sdkee package.Usually jsp pages are stored in public_html folder.
Vikas
Ranch Hand

Joined: Dec 16, 2004
Posts: 63
You should place your bean class in the WEB-INF/classes/ and then check it.

Thank you
Vikas
Nitin Jawarkar
Ranch Hand

Joined: Dec 18, 2004
Posts: 79
Hi,

First of all define the package name for u r .java file on the top like
package temp;

Then in usebean tag use that package name like
class="temp.file_name"
file_name is u r .java file name. ok
definatly it will work.
good luck...


Cheers<br />Nitin
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you're interested, I have an example app "SimpleBean" that does what you're trying to do. It's a war file that's all packaged and ready to go.

http://simple.souther.us

Sometimes an example is worth a thousand words.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to use usebean