Forums Register Login

Assignment Servlets-4a Videos

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
the ActionServlet I'm talking about is in the jr.jar
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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 ]
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.
straws are for suckers. tiny ads are for attractive people.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1422 times.
Similar Threads
JDBC-3 Why doesn't ......
<error-page> tag mechanism
How to package a project and install in tomcat webapps?
Servlets 4a(AddVideoServlet)
play vedio in jsp
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:54:15.