Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!

Jason Qiu

Greenhorn
+ Follow
since May 20, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jason Qiu

Velocity and Structs are excellent implemention of MVC for Java servlets.
They are also very popular applications for Servlets development now.
Check them on http://jakarta.apache.org
I think it may depends on the Container.
So don't use like that becoz all will confusing
The sytax of addXXX and setXXX is excatly the same.
See below:
doGet(req, res){
res.setHeader("content_type", "text/html");
res.setIntHeader("content_length", 1029);
res.setDateHeader("last-modified", 100000000);
}
Note, here, we all use setHeader, becoz this header data may already exists for default. If you use addHeader, it may not effect.
Normally, we use setHeader instead of addHeader in response .
doGet(req, res){
req.addHeader("accept_type", "image/gif, image/jpeg");
req.getRequestDispatcher("newServlet").forward(req, res);
}
Here I use addHeader for the accept_type of request, becoz an accept type may already exists for the request, I don't want to overwrite it, so add it. and Forward it to a new servlet, the new servlet may can return a image/gif or image/jpeg.
Yes, it's typo mistake.
XML declaration should begin with <?
end with ?>
and put on the first line of the XML file.
addDateHeader, addHeader, addIntHeader
will always add a response header with the given name and integer value. This method allows response headers to have multiple values.
you can then use
request.getHeaders(name) to retrieve the muliple values of one header name.
setHeader, setDateHeader, setIntHeader
set a response header with the given name and value. If the header had already been set, the new value overwrites the previous one.
you can use
request.getHeader(name) to retrieve the single values of the header name.
addDateHeader, addHeader, addIntHeader
will always add a response header with the given name and integer value. This method allows response headers to have multiple values.
you can then use
request.getHeaders(name) to retrieve the muliple values of one header name.
setHeader, setDateHeader, setIntHeader
set a response header with the given name and value. If the header had already been set, the new value overwrites the previous one.
you can use
request.getHeader(name) to retrieve the single values of the header name.
Question 25>>
Answer is 4
The doAfterBody() will not be executed because the body class extends TagSupport, not BodyTagSupport.
The doStartTag() method returns EVAL_BODY_INCLUDE, ensuring that the tag body will be printed. The result is that Hello will be printed.

doAfterBody() is defined in IterationTag and implemented by BodyTag.
doInitBody is defined in BodyTag and implemeneted by BodyTagSupport.
So it works.
[ May 22, 2003: Message edited by: Jason Qiu ]
Maybe
Sun Certified Enterprise Architect for J2EE Study Guide
is just what I want.
Anyone has experience to buy it from oversea?
I live in China Shanghai.
I have pass SCJP, and ready for SCWCD in this week.
I am hoping to take SCEA to prove my ability after I have got the SCWCD. I use the Sybex books Study Guide for SCJP and SCWCD in my prepration.
But I cannot find any titles about SCEA here.
Anyone can remmend me the SCEA title? and if I want it shipped to China, how much is it?
can anybody pls let me know the difference between the methods:
1.getServletContext()
2.getServletConfig().getServletContext()
How does the ServletContext returned by these two methods differ?
There is no any difference!
Acctually, they are the same method.
Please note that the GenericServlet implements the ServletConfig interface as well as Servlet interface. And all HttpServlets are children of GenericServlet.
getServletContext() is defined in ServletConfig interface and is implemented in GenericServlet.
So you can use either the getServletContext() of HttpServlet or use the getServletContext() of the ServletConfig.
They are absolutely the same!
Question No 26 �
Given the following tag handler defined with <bodycontent>JSP</bodycontent>
public class body extends BodyTagSupport {
public int doAfterBody() throws JspException {
try { pageContext.getOut().print("how are you?"); }catch(IOException e) {}
return SKIP_BODY;
}
}
what will be printed out by the following part of a jsp page?
<prefix:sufix>
<i>Hello</i>
</prefix:sufix>
1) The tag handler won't compile.
2) The jsp page will print Hello how are you?
3) The jsp page will print how are you? Hello
4) The jsp page will print Hello
There is no listed correct answer here.
The jsp page will print nothing.
"Hello" is the body content here, if you want to print it, you will need to use getBodyContent().writeOut(getPreviousOut()); to write the content.
The pageContext.getOut() here is still the JSPWriter object for the tag. But because
it is buffered in BodyTagSupport by default, it will print to it's own JSPWriter, but not the out JSPWriter of the page. You cannot see anything print out here.
If we overwrite the doStartTag() here and return as EVAL_BODY_INCLUDE. It will not call setBodyContent adn doInitBody() then. The process will just like the TagSupport(), all print are to the JSPWriter of the page directly.
Here will print
Hello, How are you?
Question No 24, 25, 26 are good examples for how the output will looks like for custom Tag implemention.
For question no 25
Given the following tag handler defined with <bodycontent>JSP</bodycontent>
public class body extends TagSupport {
public int doStartTag() throws JspException{
return EVAL_BODY_INCLUDE;
}
public int doAfterBody() throws JspException {
try { pageContext.getOut().print("how are you?"); }catch(IOException e) {}
return SKIP_BODY;
}
}
what will be printed out by the following part of a jsp page?
<prefix:sufix>
<i>Hello</i>
</prefix:sufix>
1) The tag handler won't compile.
2) The jsp page will print Hello how are you?
3) The jsp page will print how are you? Hello
4) The jsp page will print Hello
I am quite sure the correct is Hello how are you?
No 2. not No 4 in the answer sheet.
You can sure print using pageContext.getOut() from doAfterBdoy in a TagSupport.
Note that TagSupport doesn't provide bodyContent object because it is defined in BodyTag interface which is implemented in BodyTagSupport
about question 3:
Yes,
it equals to
<%
java.lang.String name = new java.lang.String();
out.println(name);
%>
The name is initilized as an empty String.
So it compile OK and print nothing.

about question 13:
<jsp arams> is child tag of <jsp lugin ...>
So the answer 3 is correct.