• 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

getting null in second servlet

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

i have 2 servlets called signup.java and submitfavourite.java

i am trying to pass a variable username from signup to submitfavourite like this...

code for signup.java



code for submitfavourite.java



but in my database i am getting null instead of username means session.getAttribute("uname") is returning null. i also tried this by request.getAttribute but that is also returning null.
please help me why it is returning null..

thanhx.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please properly indent your code when posting, unindented code is very hard to read. Also you should be following established naming conventions for Java. Class names should be Signup and SubmitFavourite,
 
Sachin Kadian
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry sir but now it have done it..
please help me.
 
Ranch Hand
Posts: 344
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is "req" in submitfavourite.java referring to? Should it be "req1" instead?

Also note that creating SQL by concatenating strings together is prone to SQL injection. You want to use binding variables instead.
 
Sachin Kadian
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sir i also tried with req instead of req1 but same null is returning.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll get more help if you re-post your code with proper indentation and following conventions.
 
Koen Aerts
Ranch Hand
Posts: 344
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:You'll get more help if you re-post your code with proper indentation and following conventions.


That's right, it's currently difficult to read and I'm not sure if some errors like the one below are just a formatting issue or actual mistake in the code:

(notice the quote character after the username variable)
 
Sachin Kadian
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
code for SignUp






code for SubmitFavourite




 
Sachin Kadian
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
now is it okay or should i do anything else sir???
 
Koen Aerts
Ranch Hand
Posts: 344
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sachin Kadian wrote:now is it okay or should i do anything else sir???


Now, now...

In one place you do request.setAttribute("uname"), but in the other you then do session.getAttribute("uname")... did you try request.getAttribute("uname") instead?
 
Sachin Kadian
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ohh yaa.. that was realy an error sir.. i did it by mistake. thanhx for showing this... now it is working properly.. thanhx a lot.
 
reply
    Bookmark Topic Watch Topic
  • New Topic