Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet error building

 
mark smith
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • 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?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to put the class in a package
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,



and change your jsp page


bye for now
sat
 
mark smith
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • 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 Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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: 251
  • Mark post as helpful
  • send pies
  • 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 Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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: 251
  • Mark post as helpful
  • send pies
  • 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 Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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: 251
  • Mark post as helpful
  • send pies
  • 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 Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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: 251
  • Mark post as helpful
  • send pies
  • 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 Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic