• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

servlet error building

 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi


i have a jsp who call this servlet


my user class


my student_menu.jsp



when pType = 0 student_menu is called
i get the error



any idea?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try to put the class in a package
 
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,



and change your jsp page


bye for now
sat
 
mark smith
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok work fine.....

in myLogin.java file i do:

user.setUserName(pUserName);
System.out.println("1 - pUserName" + user.getUserName());

i get the correct value...

in my student_menu.jsp file i do


Bonjour
<%= user.getUserName() %>

i get null

any idea
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You set the bean in the request scope:
request.setAttribute("user",user);

but get it back in the session scope:
<jsp:useBean id="user" class="User" scope="session"/>
A new bean is created, that is why the name is null.

Replace the scope with "request"
 
mark smith
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Satou kurinosuke:
You set the bean in the request scope:
request.setAttribute("user",user);

but get it back in the session scope:
<jsp:useBean id="user" class="User" scope="session"/>
A new bean is created, that is why the name is null.

Replace the scope with "request"



if i replace scope by request, i forwarded to errorlogin.jsp
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you set the package name to retrieve your bean ?
<jsp:useBean id="user" class="mypackage.User" scope="request"/>
[ March 08, 2006: Message edited by: Satou kurinosuke ]
 
mark smith
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Satou kurinosuke:
Did you set the package name to retrieve your bean ?
<jsp:useBean id="user" class="mypackage.User" scope="request"/>

[ March 08, 2006: Message edited by: Satou kurinosuke ]



in my User.java i have
package mypack.test;

in student_menu.jsp

<jsp:useBean id="user" class="mypack.test.User" scope="session" />
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A quick way to spot the problem would be to printout the stack trace in your catch clause (Login.java).
 
mark smith
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Satou kurinosuke:
A quick way to spot the problem would be to printout the stack trace in your catch clause (Login.java).



 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me confirm one thing :
Did you replace
<jsp:useBean id="user" class="mypackage.User" scope="session"/>
by
1. <jsp:useBean id="user" class="mypackage.User" scope="request"/>
or by
2. <jsp:useBean id="user" class="mypackage.User" request="session"/>

You should be using number one.
 
mark smith
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok work now.....

i restarted eclipse... strange...

what i need to change to use: session instead request?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Login.java, you have :
request.setAttribute("user",user);
which means that the user bean is in the request scope.
To get it back in your jsp file, you have to use <c:useBean> with the same scope, which is "request". If you use the "session" scope, you will not get your bean back.
 
What? What, what, what? What what tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic