Jim So

Greenhorn
+ Follow
since Mar 18, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Jim So

I am all good now thanks. Re-read page 356

If type is used withut class, the bean must already exist.

If class is used (with or without type) the class must not be abstract, amd must have a public no-arg constructor.
Hey im preparing for SCWCD and reading HF Servlets. Im a little confused with jsp:useBean.

If you have an existing value (dont worry about scope).

Do you use the class attribute or the type attribute to retrieve the existing value? Or can you use either.

I thought these are the rules, am i correct?

1. You can use either either class or type or both class and type attributes to retrieve an existing bean object in scope provided.
Is this correct?

2. You can use class if you dont have an existing bean object in scope and need to create a new bean instance

3. You cant use type f you dont have an existing bean object in scope and need to create a new bean instance
I have seen jsp.directive.page and jsp.directive.include used plenty of times before. But never jsp.directive.taglib

This prompted me to check whether you can.

Searching the web i found some places that mentioned they use it.

But i also found some stating something similar to this:

"The action jsp:directive.taglib does not exist.
Use namespaces instead
Code:
<jsp:root xmlns:c="http://java.sun.com/jstl/core">"

So has jsp.directive.taglib become obselete? Do i assume that it is not a valid form of XML document syntax?

Anyone know for sure?
as i understand it. when you are asked in the mock exam questions: what are the two http authentication methods.

The answer is: HTTP basic and digest authentication
I got the following from the java spec:

"If a tag is implemented as a tag file and is packaged in /WEB-INF/tags/ or a subdirectory, a TLD will be generated automatically by the web container, though you can provide one if you wish."

Question: Is this only the case for tag files, that the container will automatically generate a TLD file? Or will the container generate TLD files automatically for say simple tag handlers and classic tag handlers too?


Thanks!


I guess a key question to help me answer this question correctly is:

Are tag files are validated at runtime or translation time?

Anyone know?
Its a Mock Exam question:
Which three occur during JSP page translation ( Choose 3)

1.jspinit Method is called
2.JSP page implementation class is created
3.JSP page implementation class is compiled
4.JSP page is validated for syntactic correctness
5.The associated tag files are validated for syntactic correctness


i think the correct answer is 2,4,5.

I am not sure about #5 though. I cant find any documentation in any of the books or online about whether the tag files are validated and checked for syntatic correctness during JSP page translation. BUt i assume they are.

I think its 2,4,5 because:

Because #1 is incorrect - jsp init method is called later on (after loading the class and then instantiating the class)

Because #3 is incorrect - because class compilation occurs after page translation according to what i read about the life cycle of a jsp: Compilation is a seperate step that happens after translation.


Who agrees or disagrees with me? Im not sure if i am actually right I think the mock answer was 2,3,5.
ok sure, sorry about that. Wont do it again.

So if i have a similar question raised in an old thread. But the replies didnt really confirm the correct answer. Ill can just start a new thread?
i think the answer is 2,4,5.

Because #1 is incorrect - jsp init method is called later on (after loading the class and then instantiating the class)

Because #3 is incorrect - because class compilation occurs after page translation according to what i read about the life cycle of a jsp: Compilation is a seperate step that happens after translation.

Who agrees or disagrees with me?

I believe the mock answer is 2,3,5. But i dont agree. I think 2,4,5 for the above reasons.



in the jstl specification, it states that <c:redirect> follows the same rewriting rules as defined for <c:url>

So does this mean that c:redirect does url rewriting? like c:url does?

In otherwords that mock answer is correct? a and e?

Because its sort of a contradiction, as it then discusses c:redirect and its all about redirecting to another url. It doesnt seem to have anything to do with url rewriting.


I dont like this question. No idea what the answer is.

We know c:url does url rewriting
and c:param does url encoding. And that c:param can be combined with c:url to do url rewriting and url encoding. But since c:param is url encoding, not url rewriting, i would not select "c:param" as the answer.
So that leaves c:redirect to be the only other possible answer.

So i say a and e.

But what is right?
I keep on getting confused about which types of tags can use which types of body-content values.

Can anyone provide me with a list of each?

e.g.

Custom Tags: scriptless, empty, tagdependent, JSP
Simple Tag Handler: scriptless, empty, tagdependent, JSP
Classic Tag Handler: scriptless, empty, tagdependent, JSP
Tag file: scriptless, empty, tagdependent

Is that right? you can use all of the types in any tag except that tag files cant use JSP, as they cannot accept scripting in the body?
Hi, If you forward a request in a jsp to another page, then can you still call out.println()? Or will you get a runtime error?

Also if you do

out.println("1");
RequestDispatcher view = request.getRequestDispatcher("secondJSP.jsp");
view.forward(request,response);
out.println("2");


======
second.jsp:

out.println("in second jsp");


What will be outputted to the client?

a) 1 in second jsp 2
b) 1
c) 2
d) in second jsp
e) runtime error

and if you get a runtime error, then at which point is is thrown?

If i didnt have the line out.println("2"); would it still output "1 in second jsp"?
I got this from HFS p486

Tld files can be located :
1. Directly inside WEB-INF
2. Directly inside a sub directory of WEB-INF
3. WEB-INF/lib/jar/META-INF/
4. In a subdirectory of WEB-INF/lib/jar/META-INF/

Question: If it can be located directly inside a sub directory of WEB-INF, then can a tld be located by the container if its situated within /classes or /lib ? or are these two folders not searched by the container?

I also I read the next chapter on tag files. It mentiones that you only need to declare a tld file, if the tag file is located in a jar file.
So what happens if your tag file is located inside the /WEB-INF/tags location.

Question 2: So if the tag file (Header.tag) is located in /WEB-INF/tags and there is no tld file defined. Does this mean i have to have a 'tagdir' defined in a taglib directive in my jsp:

<%@ taglib prefix="myTags" tagdir="/WEB-INF/tags" %>

<myTags:Header />

Or since the tag file is in /WEB-INF/tags, do i not need to specify the tagdir? E.g. Can i just say:

<%@ taglib prefix="myTags" %>

<myTags:Header />

Since Header.tag exists in a folder that the container searches?
I recall a question in the HeadFirstServlets+Jsp's book... i found it Chapter 5, Q1.

The answer states that if you cann os.write() or os.flush(), then the response is sent back to the client. Therefore if you try and attempt a forward, you will get an IllegalState exception.

Is this true? That both os.write() and os.flush() will cause this?