| Author |
servlet error building
|
mark smith
Ranch Hand
Joined: Apr 05, 2005
Posts: 240
|
|
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
Joined: Nov 24, 2005
Posts: 14672
|
|
|
Try to put the class in a package
|
[My Blog]
All roads lead to JavaRanch
|
 |
satishkumar janakiraman
Ranch Hand
Joined: May 03, 2004
Posts: 334
|
|
Hi, and change your jsp page bye for now sat
|
 |
mark smith
Ranch Hand
Joined: Apr 05, 2005
Posts: 240
|
|
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
Joined: Nov 24, 2005
Posts: 14672
|
|
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
Joined: Apr 05, 2005
Posts: 240
|
|
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
Joined: Nov 24, 2005
Posts: 14672
|
|
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
Joined: Apr 05, 2005
Posts: 240
|
|
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
Joined: Nov 24, 2005
Posts: 14672
|
|
|
A quick way to spot the problem would be to printout the stack trace in your catch clause (Login.java).
|
 |
mark smith
Ranch Hand
Joined: Apr 05, 2005
Posts: 240
|
|
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
Joined: Nov 24, 2005
Posts: 14672
|
|
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
Joined: Apr 05, 2005
Posts: 240
|
|
ok work now..... i restarted eclipse... strange... what i need to change to use: session instead request?
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
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.
|
 |
 |
|
|
subject: servlet error building
|
|
|