• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

How to access a local class in jsp  RSS feed

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem here with file Pjsp.jsp the code is as below

<% Person p= (person)request.getAttribute("person");%>
Person is:<%=p.getName()%>
Person is my local class stored in default package but I get a run time error as:



can anyone suggest me how to use a object of this class.
 
Author and ninkuma
Marshal
Posts: 66824
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aside from the fact that you shouldn't be putting Java code into a JSP, any beans referenced from a JSP must be in a package other than the default. This is covered in the JSP FAQ.
 
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dude,
while you typecasting ..your typed as person instead of Person
hope the following will work as you need.......


 
Vickey singh Verma
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for u'r replies.
I was just trying an example from head first JSP chapter, instead of doing manually I used Netbeans and put the java class (Person) in default package
when coding in JSP page I can see the class Person by pressing CLT+SPACE but i don't understand why it gives error on creating the object of the class i.e p.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66824
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use real words when posting to the forums. Abbreviations such as "u'r" in place of "your" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please read this for more information.

thanks,
bear
JavaRanch sheriff

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!