473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

JavaBean can be accessed from JSP but not Servlet, why?

121 100+
Generally speaking, JSP and servlet are equivalent.

I found one strange question:

I've created a JavaBean class called UserinfoBean.class and put it inside /WEB-INF/classes/uts/ait/cmao/

It could be accessed from using the <jsp:useBean class="uts/ait/cmao/UserinfoBean" scope="session" /> tag
and set/get attribute tags worked as well.

But when I tried to use a servlet to access the JavaBean, using explicit java code like:

package mypackage (all the servlets and JavaBeans are in this package);

import *

code block omitted.

user = (UserinfoBean)session.getAttribute("userinfo");

another code block omitted.

I isseded: javac myServlet.java

But the compiler refused to generate the .class file, pointing at an error that it cannot resolve symbol UserinfoBean in my java code.

I guess my CLASSPATH is okay. Otherwise the JSP page couldn't find it using the <jsp:useBean> tag.

But there must be something wrong. I followed the samples in the reference book called core Servlet and JavaServerPages, so the template should be fine.

Thank you in advance.
Sep 24 '07 #1
1 1682
dmjpro
2,476 2GB
Expand|Select|Wrap|Line Numbers
  1. <jsp:useBean name = "userinfo" class="uts/ait/cmao/UserinfoBean" scope="session" /> tag
  2.  
You can access this variable userinfo with in Session.
As long the session persists the lifetime of this variable also persists.


Kind regards,
Dmjpro.
Sep 24 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Hai Tran | last post by:
Any help is appreciated. Installed Tomcat 4.1 and Mysql on a WinXP. I've manage to get Tomcat up and was able to view my first application ( myhome ) simple home page. Tomcat was installed under...
1
by: Alex | last post by:
Hi all- I am having a little trouble storing resultset data from a javabean into an array located in a JSP page. Any other approaches, advice or links to information would be appreciated. Thanks...
5
by: opthomas | last post by:
I'm fairly new to DB2 Stored Procedures so not sure how best to go about this. I need to generate a csv file that will contain data from approximately 9 different tables - approxinmately 150...
1
oll3i
by: oll3i | last post by:
Cd u please give me the example of javabean with constrained values thank u
3
by: AnithaTolgiri | last post by:
My question is how to sort a javabean on the basis of two fields. I have to create a javabean and then sort it by some String type field and then by another String type field.When I sort it for the...
14
by: ramadeviirrigireddy | last post by:
Hi All, I have the following code for form and servlet. when the form is submitted the servlet will print the values passed by the form. i'm not getting the servlet o/p when i submit the...
2
by: judge82 | last post by:
I have two JSPs, one takes a request and the other displays the result and I am having problem with the javabean to connect the two here are my codes takes request <%@page...
9
by: mjahabarsadiq | last post by:
Hi I have created a servlet that is to be started at the server startup. And I got it. In that I have created a object of another class and set it as a session attribute. What I am trying is...
2
by: devgupta01 | last post by:
Can I use formbean in place of javabean in struts framework..? Can you please explain difference between JavaBean and FormBean? Thanks in advance....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.