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

Servlet Parameters null

 
Brooke Maddox
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I have a servlet that is supposed to get the parameters from a JSP page form, set the parameters to a bean, and then save the bean to the session. I then have another JSP page that retrieves the session and displays the parameters in a table. My problem is all of my parameters are showing up null. I can't seem to figure out what is wrong. Here is my code: PageA JSP

Controller Servlet:
Confirmation JSP

I haven't included the Model.Movie Bean code but when I set the variables in my Bean they show up in my Confirmation page so I am assuming that the Bean code is legit.
Thanks for any and all help
 
Saif Asif
Ranch Hand
Posts: 440
Eclipse IDE Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Brooke ,
<form action= "Confirmation.jsp" method ="post">

There is a slight issue in the flow of your application. You seem to be calling in the JSP directly. This is why the paremeters are wrong since your servlet is never called . The correct flow should be jsp --> servlet --> jsp . For this. You need to specify the name of your servlet here ( the ControllerServlet ) instead of the name of jsp. The name of the servlet must be the one as mapped in your web.xml deployment descriptor.
So change it to


Do post back for any further queries.
 
Brooke Maddox
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay so I changed my forms action to ControllerServlet. Now I am getting an HTTP Status 404 error, I have admin rights in my application so do I need to change my url pattern in my servlet even though my ControllerServlet is not under any admin folder?
 
Saif Asif
Ranch Hand
Posts: 440
Eclipse IDE Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brooke Maddox wrote:Okay so I changed my forms action to ControllerServlet. Now I am getting an HTTP Status 404 error, I have admin rights in my application so do I need to change my url pattern in my servlet even though my ControllerServlet is not under any admin folder?

The servlet mapping shouldn't depend on any folder hierarchy , it should be mapped properly in the web.xml only, that is from where the container will find your serlvet based on the url pattern you hit. What is your mapping in the web.xml , post it here . Also I would like you to post what change have you made in your form action attribute and lastly the URL that was hit in the browser when you got the 404 error
( must be something like http://<servere_name>:<port>/<context_name>/some/more/paths/ControllerServlet
 
Brooke Maddox
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my xml:

My JSP form

The url: http://localhost:8080/CMIS4407980_BNMProj2/secureAdmin/ControllerServlet
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The URL of your form action should be server-relative; that is, start with the context path. See the JspFaq for more info.
 
Saif Asif
Ranch Hand
Posts: 440
Eclipse IDE Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems that your URL is going in the context http://localhost:8080/CMIS4407980_BNMProj2/secureAdmin/ControllerServlet while my best guess ( since you also mentioned that the servlet is outside the admin realm ) is that it should be something like http://localhost:8080/CMIS4407980_BNMProj2/ControllerServlet .

As Bear said , go through the FAQ forum and try to search for how to do this.
Hint : Your issue is just related to paths .
 
Brooke Maddox
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear I found the topic on server-relative context paths. Now I seem to lose my connection to the localhost:8080 every time I run the application. Here is my new form

I added the following to my xml
 
Paul Clapham
Sheriff
Pie
Posts: 20945
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brooke Maddox wrote:Now I seem to lose my connection to the localhost:8080 every time I run the application.


What makes you think that?
 
Brooke Maddox
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Must have been a glitch with my server b/c now its not doing it. But my parameters are still null
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post an updated SSCCE
 
Brooke Maddox
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PageA JSP

ControllerServlet
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And you have determined that the params are null, how...?
 
Brooke Maddox
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Confirmation JSP page that should post the parameters but they are all null. Here is the code for this page:
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's no proof that the params are null. There are many places along the pipe where things can go awry. In fact, the problem is not in the servlet.

And, why use the session rather than request scope? (Hint, hint)

(And, scriptlets in the JSP? Really?)
 
Brooke Maddox
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for all your help, as you can see I have a lot to learn
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you find the problem? (I dropped a pretty big hint.)
 
Brooke Maddox
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, thank you for all your help Bear!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64683
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For others following along, the servlet placed the scoped variable in session scope, but the JSP looked for it in request scope.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic