• 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

request attribute problem in Jsp

 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all
function doLogin(){
var id= loginForm.UID.value;

if(id.length > 0 && id.charAt(0)!=" "){
<% request.setAttribute("action","checkUser"); %>
//<% session.setAttribute("action","checkUser"); %>

document.loginForm.submit();
}else{
alert("Enter User Name");

}
}
In the code above i am trying to set the request parameter "Action" to a value.. but when i try to access it in the servlet it is posted to i get a null value. But if i put it in the session than it works fine.
My servlet is acting as a controller and forwards the request to another bean or servlet depending upon the "action" value passed in the request.
Can anyone help me with what the problem is and what solution can be. Personally i dont want to use the session for it.
Thanks Dave for help, and everyone else also.
Gul
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah (or AAAarrrrrr), now it becomes clear.
You can't mix JavaScript and KSP code in the way. JavaScript occurs on the client, but Java code occurs on the server.
Check out this thread for someone having the same problem.
The code you are executing always gets executed before the response is sent to the client. Nothing happens with the Java code when they run the function on the client, it is already too late.
Dave
 
Gul Khan
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So if it is working in the session.setAttribute it means it gets set before the page is loaded and not after the button is clicked?
And will it be better to use hidden fields or is there any other way i can use to pass a value to the servlet.
Gul
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Correct.
Passing the parameter back via a hidden field is the standard.
It is often prefered to keep data in the request scope rather than using the session. A fairly broad definition I use is that the only data that goes on the session is data that is true for the life of the session. ie it should be valid regardless of the page the user goes to. Getting it roight is a matter of practice
 
Gul Khan
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks David. you have helped me alot today. looking forward to your words of wisdom again soon.
Gul
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic