Step 2 - some servlet that is somehow mapped to process this request sets the commentList attribute and the userType attribute like I described earlier. Then, this servlet dispatches to some view - in this case, the view is actually the JSP which has the "c:if" code. Let's call this JPS as MajorJSP.

Step 3 - The MajorJSP realizes that the userType is a member, so it tells the container to include some other code in it. This other code is actually the inputComments.jsp.

Step 4 - The user now can see the part of the page where he/she can input his/her comments. So the supposelly write a comment and hit the submit button, which has a value "Add Comment". Then, this request is send to some other JSP (the third one) called commentsProcess.jsp to proccess the user comment just added. This jsp (commentProcess.jsp) is not being showed on the page.

Got the point now? [ July 31, 2005: Message edited by: Leandro Melo ]

Leandro Melo
SCJP 1.4, SCWCD 1.4

Darya Akbari

Ranch Hand

Posts: 1855

posted 11 years ago

Hi Leandro,

I appreciate your comments , however I still didn't get it all. I agree with you on Step 1, Step 3 and Step 4. However I do NOT agree on Step 2's first part:

some servlet that is somehow mapped to process this request sets the commentList attribute ...

because page inputComments.jsp contains this line:

To me it says that NOT another second servlet is handling this request BUT the JSP file commentsProcess.jsp, which takes the input from inputComments.jsp due to post, is handling the commentList attribute.

Now, let's say we have the following files:

MajorJSP.jsp (given)

inputComments.jsp (given)

commentsProcess.jsp (unknown so far, but I want this)

MemberServlet.java (Servlet that represent Tester.do and set userType = "member" upon request)

web.xml (mappig MemberServlet/Tester.do)

How does commentsProcess.jsp looks like ? Any suggestions are welcome

Regards, Darya

SCJP, SCJD, SCWCD, SCBCD

Leandro Melo

Ranch Hand

Posts: 401

posted 11 years ago

Originally posted by Darya Akbari:

How does commentsProcess.jsp looks like ? Any suggestions are welcome

Darya, there's no second servlet!!! There's just one. The commentsProcess.jsp is NOT there. It's just for us to imagine how it would handle the user input comment! The commentList attribute has NOTHING to do with the commentsProcess.jsp. Take a look at the pictures. The value of the commentList attributes is this:

------------------------------ This site rocks.

This site is cool.

This site is stupid. ------------------------------

The commentList is (supposedly) set by the SAME servlet the sets the userType attribute. Take a look at both pictures on that page. The first one is for the case when the "c:if" returns TRUE. The second picture is for the case when the "c:if" returns FALSE. So, in the second picture, the inputComments.jsp is NOT present, because the "c:if" returned FALSE. So, also the is not present either. However the commentList is there anyway, because it was to by the servlet the dispatched to the MajorJSP.

Well, that's my last shot!

Leandro Melo
SCJP 1.4, SCWCD 1.4

Darya Akbari

Ranch Hand

Posts: 1855

posted 11 years ago

Leandro,

whether that is your last shot or not we will see . I know what you say, it's already explained on HFSJ p. 441.

You miss the point . The point is: I WANT TO FILL THE GAP

Or in other words, I take this as an exercise and want to make this incomplete example (p. 441) complete. I want this example to become something tangible or better said runnable.

If you feel you can provide a runnable solution then I very much appreciate to see your solution based on p. 441 otherwise let others come forward.

Regards, Darya

SCJP, SCJD, SCWCD, SCBCD

Leandro Melo

Ranch Hand

Posts: 401

posted 11 years ago

Originally posted by Darya Akbari:

whether that is your last shot or not we will see

Ok, you win. That was not my last shot :roll:

What you have been asking since your first post is "how do I set the commentList". You did not understand how this "commentList" thing was working. You said that it was not the way that I explained (even when I explicitly mentioned the steps). Ok, try this code then and you'll see how the commentList works.

NOTE: You have to name the the first jsp on page 441 by MajorJSP, like this. This is Major.jsp (from page 441)

DD

Servlet.

commentsProcess.jsp

Leandro Melo
SCJP 1.4, SCWCD 1.4

Darya Akbari

Ranch Hand

Posts: 1855

posted 11 years ago

Leandro,

no no no, I am not looking for a hardcoded solution as I said previously.

Why do you think is the Add Comment button? It's there to add comments dynamically. So use it.

You always ship around the real challenge. To hardcode the entries and to assign them to commentList is like you want to betray me. You are definitly not filling the gap.

And remember you should post here a runnable version!

Regards, Darya

SCJP, SCJD, SCWCD, SCBCD

Leandro Melo

Ranch Hand

Posts: 401

posted 11 years ago

Originally posted by Darya Akbari:

no no no, I am not looking for a hardcoded solution as I said previously.

Ok then, so just imagine that you have a DB access that returns a List with all the records. And then you create a String with the List, the same way, by calling setAttribute().

Anyway, to build a working solution (for a real world) you'd have to have Database access (if you want that, maybe you can find some tutorials or books about accessing DB in j2ee). I'm not posting a real solution because I don't have time. I just don't get why can't you just abstract this part. Whatever... I hope at least, that you understand how the commentList attribute got there (which was your primary question). I'm done. Sorry I couldn't help you to build the real working solution. Anyway, if your second point is building the real thing, is better to go to the JSP/Servlet forums.

Leandro Melo
SCJP 1.4, SCWCD 1.4

Darya Akbari

Ranch Hand

Posts: 1855

posted 11 years ago

Leandro,

this is not an easy topic and I really appreciate your efforts to help me out to fill the gap. Unfortunately we couldn't reach a solution.

Thanks for your patience with me .

Now, isn't there anyone out there in the SCWCD space who can help ?

Regards, Darya

SCJP, SCJD, SCWCD, SCBCD

Bryan Basham

author
Ranch Hand

Posts: 199

posted 11 years ago

Hello Darya,

I think what you are looking for is the code for commentsProcess.jsp.

I would do something like this:

Note that this JSP should really be a servlet as this is a Controller component and in an MVC application you should use servlets (or Struts action objects) for Controller components.

Also, if this were the code for commentsProcess.jsp, then the code in major.jsp is not quite correct as the output of ${commentList} would not be formatted as the screen snapshots show.