Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting null in second servlet

 
Sachin Kadian
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
sorry sir but now it have done it..
please help me.
 
Koen Aerts
Ranch Hand
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
sir i also tried with req instead of req1 but same null is returning.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
code for SignUp






code for SubmitFavourite




 
Sachin Kadian
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
now is it okay or should i do anything else sir???
 
Koen Aerts
Ranch Hand
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic