aspose file tools*
The moose likes Cattle Drive and the fly likes Assignment Servlets-4a Videos Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Assignment Servlets-4a Videos" Watch "Assignment Servlets-4a Videos" New topic
Author

Assignment Servlets-4a Videos

Tony Smith
Ranch Hand

Joined: Jul 07, 2007
Posts: 229
I was woarking on the assignment and notices everytime I add a video, it only displays the latest one video I added. Previously added video are gone. I think that is the problem with request attribute. Once I send it to a JSP page, it no longer persist across other JSP page that I may browse into. The only solution I can think of is using session and store attribute there. Is that how I should do it?
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
That's one way to do it. I think a better way would be to avoid browsing directly from one jsp to another. Let your servlet be in control.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Tony Smith
Ranch Hand

Joined: Jul 07, 2007
Posts: 229
Am I not suppose to have listvideo.jsp and addvideos.jsp? How can I just have 1 jsp? After listvideo.jsp displays the video I added before whenever I go to addvideos.jsp to add more video the original object is lost.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
You should have 2 jsps. However each of those jsps is controlled by the servlet. You should not go directly from one jsp to the other. jsp#1 sends its info to the servlet which forwards that same info to the jsp#2. Likewise, jsp#2 sends its info to the servlet before the servlet returns you to jsp#1. The servlet controls which jsp is shown.
Tony Smith
Ranch Hand

Joined: Jul 07, 2007
Posts: 229
Hmmm, what should I use as the separation technique inside the servlet though? Should I have some kinda of if else statment to separate request coming from one jsp or the other? And what would be the key to use for determining the separation?

Also I just tested out, it doesn't make difference if I go to another jsp or another servlet, the request attribute is lost. Seems like from the JSP page I need to manually forward the request to the destination jsp or servlet. Just by clicking hyperlink, doesn't forward the request.

What is the syntax to forward the request from JSP?
[ October 04, 2007: Message edited by: Tony Smith ]
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1344
    
  12
Have you looked at the methods in the ActionServlet class? There is a method there that will send the user to the specified place, and send along the data as well.
Tony Smith
Ranch Hand

Joined: Jul 07, 2007
Posts: 229
Isn't ActionServlet part of the struts framework? I thought for the assignment we suppose to keep it simple and use basic servlet and jsp to solve the problem.
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1344
    
  12
the ActionServlet I'm talking about is in the jr.jar
Tony Smith
Ranch Hand

Joined: Jul 07, 2007
Posts: 229
Are you talking about forward() method? That is pretty similar to requestdispatcher which reguar servlet has already.

That does not address the problem that I have. Assuming 1 servlet is taking care requests coming from 2 jsps. How can the servlet tell if it's from first or second jsp?

And I am already using servlet, just in case you were confused on my previous post. The step shoud go like this:

addvideo.jsp ==> servlet ==> displayvideo.jsp
(This part works fine) but if I continue to add another video:

displayvideo.jsp ==> addvideo.jsp ==> servlet ==> displayvideo.jsp

notice the first video I added is gone. If I don't use session, then I need to figure out how to forward request between JSPs and keep the request object alive.
[ October 04, 2007: Message edited by: Tony Smith ]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
We're talking about the abstract init() method in the jr.jar ActionServlet class which you should override (your VideoServlet should extend com.javaranch.common.ActionServlet). You did download jr.jar in the OOP-1 assignment, right? It contains the source code as well as the .class files which you can see if you unjar the jar file.

We don't teach struts in the Cattle Drive.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
Originally posted by Tony Smith:
And I am already using servlet, just in case you were confused on my previous post. The step shoud go like this:

addvideo.jsp ==> servlet ==> displayvideo.jsp
(This part works fine) but if I continue to add another video:

displayvideo.jsp ==> addvideo.jsp ==> servlet ==> displayvideo.jsp
... the first video I added is gone.

The steps should go like this:
addvideo.jsp ==> servlet ==> listvideos.jsp
listvideos.jsp ==> servlet ==> addvideo.jsp ==> servlet ==> listvideos.jsp

Your jsp sends a parameter to the servlet to let it know which jsp it is. This could be handled by an if statement, but using the init method is simpler and cleaner.
[ October 05, 2007: Message edited by: Marilyn de Queiroz ]
Tony Smith
Ranch Hand

Joined: Jul 07, 2007
Posts: 229
Ok, let me ask this one last question before I give it a rest. I did not realize I am suppose to use actionhandler and actionservlet stuff from previous assignment. I guess I didn't quite understand how it work back then, so that's probably the reason I am not thinking of using it. I still have some doubts on addActionHandler method. Let's say you have:


public void init()
{
addActionHandler( "abc" , new Default());
}

I know I am suppose to pass in parameter to match abc. But is abc only matching parameter key from doget? So I can have anything in parameter value it will be ignored right?

so let's say the link is
http://localhost/something?abc=somevaluethatwillbediscarded

Is that the idea?
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
yes ... and no.

Rather than http://localhost/something?abc=somevaluethatwillbediscarded, you should have something more like
http://localhost/something?action="abc"

Different pages pass in different actions.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Assignment Servlets-4a Videos
 
Similar Threads
Servlets 4a(AddVideoServlet)
How to package a project and install in tomcat webapps?
JDBC-3 Why doesn't ......
play vedio in jsp
<error-page> tag mechanism