This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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: 66532
160
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: 66532
160
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!