Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes Servlet Parameters null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Parameters null" Watch "Servlet Parameters null" New topic
Author

Servlet Parameters null

Brooke Maddox
Ranch Hand

Joined: Nov 23, 2012
Posts: 42
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

Joined: Aug 11, 2011
Posts: 440

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.


Muhammad Saif Asif Mirza
OCJA(5/6) OCJP(6) OCJWCD(6)
Brooke Maddox
Ranch Hand

Joined: Nov 23, 2012
Posts: 42
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

Joined: Aug 11, 2011
Posts: 440

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

Joined: Nov 23, 2012
Posts: 42
Here is my xml:

My JSP form

The url: http://localhost:8080/CMIS4407980_BNMProj2/secureAdmin/ControllerServlet
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60764
    
  65

The URL of your form action should be server-relative; that is, start with the context path. See the JspFaq for more info.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Saif Asif
Ranch Hand

Joined: Aug 11, 2011
Posts: 440

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

Joined: Nov 23, 2012
Posts: 42
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Nov 23, 2012
Posts: 42
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

Joined: Jan 10, 2002
Posts: 60764
    
  65

Post an updated SSCCE
Brooke Maddox
Ranch Hand

Joined: Nov 23, 2012
Posts: 42
PageA JSP

ControllerServlet
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60764
    
  65

And you have determined that the params are null, how...?
Brooke Maddox
Ranch Hand

Joined: Nov 23, 2012
Posts: 42
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

Joined: Jan 10, 2002
Posts: 60764
    
  65

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

Joined: Nov 23, 2012
Posts: 42
Thank you for all your help, as you can see I have a lot to learn
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60764
    
  65

Did you find the problem? (I dropped a pretty big hint.)
Brooke Maddox
Ranch Hand

Joined: Nov 23, 2012
Posts: 42
Yes, thank you for all your help Bear!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60764
    
  65

For others following along, the servlet placed the scoped variable in session scope, but the JSP looked for it in request scope.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Parameters null
 
Similar Threads
Text Box Validation
jsp insert program not working
Error coming 500 please an code is
How to retrieve value from .js and show the values in jsp ?
Display Result on Same Page?