• 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

Bogging down a bit.....

 
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've made a start on VideoServlet, but I'm at an impasse.
The index page shows up when I point my browser to http://localhost/videos/
Which is good, but when the list videos link is clicked, only a blank page appears. This message is printed out in the dos window: exception in doGet():java.lang.NullPointerException

If I point my browser to http://localhost/videos/addvideo.jsp I see the form for adding a video, and if I try to add a video, when I click on the button I get sent to /videos/VideoServlet, and the table I created in listvideo.jsp appears with null values in each cell. Obviously my servlet isn't working yet.
I've created a static ArrayList to hold my VideoData objects, and a getList() method for retreiving the ArrayList, because that's what I did for this assignment when it was all servlets talking to each other instead of servlets and jsps. I don't see why it won't work, but it won't.
Getting the parameters, setting Attributes and getting Attributes, and forwarding is basically the same as I did in the Reverse2Servlet, but the videos aren't being added to the ArrayList (at least I don't think they are, I've no way of really knowing that) and they definately aren't being listed in the table.
I also can't figure out what's going on with the NullPointerException. I think it's happening when doGet() calls processAction(), probably because there is no parameter named action to pass into the method along with the servletData, but I'm not sure what to do about it!
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Carol,

What does your doGet() do in VideoServlet?


[ April 14, 2006: Message edited by: Marilyn de Queiroz ]
 
Carol Murphy
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The forwarding part seems to work from both addvideo.jsp and listvideo.jsp, but doGet() isn't being called from VideoServlet. What I don't understand is why.
[ April 14, 2006: Message edited by: Carol Murphy ]
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
doGet is called on the servlet when you click on the link from index.html
Let's see what could be causing a NullPointerException in your Default class. You haven't done a post, so you can skip the if block and go straight to the else block. What do you see in there that might be causing a NullPointerException? To verify, I would pull that out and check
<pre>if ( theObject == null )
{
System.out.println( theObject is null );
}</pre>
 
Carol Murphy
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marilyn de Queiroz:
doGet is called on the servlet when you click on the link from index.html
Okay, so doGet() is being called, but there's a problem.

Let's see what could be causing a NullPointerException in your Default class. You haven't done a post, so you can skip the if block and go straight to the else block. What do you see in there that might be causing a NullPointerException?

Okay, it's not videoList. I wanted to print it in the servlet, but that wasn't working. The message was printing in the dos window, and videoList is not null. The only other things I can think of are listvideo.jsp not being a servlet yet, or the request in doGet is null. But I'm still confused.


To verify, I would pull that out and check
<pre>if ( theObject == null )
{
System.out.println( theObject is null );
}</pre>
QUOTE]
[ April 17, 2006: Message edited by: Carol Murphy ]

 
Carol Murphy
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't find any null objects. addvideo.jsp is working. The videos are being added to the ArrayList, but I can't get past the null pointer exception in doGet(). I can't find the null object.
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The other thing it might be is

in the forward statement. Paul and I were doing some pair programming and we ran into this problem. When you access listvideo.jsp directly in the server, what is the url? i.e. something like http://localhost/listvideo.jsp ?? or is it something similar but not exactly?

We're going to do a little more testing and then update jr.jar to be a little more informative if someone runs into this situation.

And we'll probably get rid of the PathFinder class.
[ April 19, 2006: Message edited by: Marilyn de Queiroz ]
 
Carol Murphy
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You know, I was looking at that, but I wasn't sure how to proceed with testing it. I think I saw a method for getting the uri or url somewhere. I will do a litle more research. It would explain the blank page and the doGet() exception, but not why the listvideo.jsp doesn't work. Baby steps, I guess!

1) http://localhost/videos/servlet/VideoServlet
2) http://localhost/videos/servlet/VideoServlet
3) http://localhost/videos/listvideo.jsp

1) the address of the page that is produced when the list videos link from http://localhost/videos/ has been clicked. Produces blank page and doGet() exception message in dos screen.
2) the address of the page that is produced when the add video button is clicked in the form at http://localhost/videos/addvideo.jsp This page displays the table I want, but there is one row of null values.
3) this address displays a page identical to the one shown by 2).

Seems I have some work to do!
[ April 20, 2006: Message edited by: Carol Murphy ]
 
Carol Murphy
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I just thought of something that might work, but I'm not at home. If I replace the string literal inside forward() with a call to one of the methods from PathFinder that redirects a request from the servlet to the jsp, that might solve the null pointer problem. But wait, if "listvideo.jsp" is a String, than that can't be the null pointer. The null pointer must be in with the servletData. Poop. Now I have to figure out how to get at the servletData to see if it's the source of the null pointer.

Another thought! Could I use the getPathFromJSPToUnMappedServlet() instead because the index.html is in the same directory as the jsp's?

I just downloaded jr.jar to this computer, and it won't allow me to open the file. There's an alert window from the Java Virtual Machine Launcher that contains this message: Failed to load Main-Class manifest attribute from C:\Documents and Settings\student\Desktop\jr.jar
What does that mean? (Other than something important failed to happen)
[ April 21, 2006: Message edited by: Carol Murphy ]
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Originally posted by Carol Murphy:
Okay, I just thought of something that might work, but I'm not at home. If I replace the string literal inside forward() with a call to one of the methods from PathFinder that redirects a request from the servlet to the jsp, that might solve the null pointer problem.


Yes. That would work.

Another thought! Could I use the getPathFromJSPToUnMappedServlet() instead because the index.html is in the same directory as the jsp's?

Are you going fromJSPToServlet or from ServletToJsp?

I just downloaded jr.jar to this computer, and it won't allow me to open the file. There's an alert window from the Java Virtual Machine Launcher that contains this message: Failed to load Main-Class manifest attribute from C:\Documents and Settings\student\Desktop\jr.jar
What does that mean? (Other than something important failed to happen)


You can open it with WinZip or on the command line with 'jar tvf jr.jar' (from the directory where the jar is located) if you want to see the file names, or 'jar xvf jr.jar' to extract the files. (If you use jar ..., leave the quote marks off).

But wait, if "listvideo.jsp" is a String, than that can't be the null pointer. The null pointer must be in with the servletData. Poop. Now I have to figure out how to get at the servletData to see if it's the source of the null pointer.

The NullPointerException is caused by the forward method which uses RequestDispatcher. The ServletRequest calls a method -- public RequestDispatcher getRequestDispatcher(java.lang.String path) which returns null if it can't finds the page you've specified. Then when tries dispatcher.forward(), it throws an exception because the dispatcher is null.
 
Carol Murphy
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marilyn de Queiroz:


Are you going fromJSPToServlet or from ServletToJsp?



In this case, I guess it would be from Servlet to JSP. I was thinking that since the page making the request was in fact the index.html, and the request was being sent to VideoServlet I would call the method that would find the path from a file in the same directory as the jsp's to an unmapped servlet. But the request is actually being sent from the servlet to a jsp, since the requested page is the one which should display the list of videos, right? (if I can get the code to work!)
 
Carol Murphy
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, my idea didn't work. I don't know if it was faulty implementation or something else, but the compiler didn't like me putting PathFinder.getPathFromServletToJSPForRedirect + "listvideo.jsp" in place of the string literal I was trying to use. Still a null pointer exception. I'm going to go take a hot bath and drink a case of beer. Goodnight!
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you doing a redirect or a forward? Perhaps you have an old version of PathFinder that doesn't have a mathod named "getPathFromServletToJSPForForward" ??
[ April 21, 2006: Message edited by: Marilyn de Queiroz ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic