Romy Huang

Ranch Hand
+ Follow
since Sep 30, 2003
Merit badge: grant badges
For More
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 Romy Huang

just HttpSessionsBindingListener and HttpSessionsActivationListener don't need to register in web.xml. But I find these in spec. Can any one find it?
[ March 08, 2005: Message edited by: Romy Huang ]
If I HttpSession.setMaxInactiveInterval(-1), May I use invalide() to expire the session? Thanks.
what order it is in listener register?
Is it dependend on listener declaration in DD?
what is difference between ServletContext and request getRequestDispatcher?
Problem

Consider the following JSP code (See exhibit).
What will it print for the very first request to this page as well as the web application that contains this page?

Code

<html><body>
<%
Integer count = (Integer) request.getSession(false).getAttribute("count");
if(count != null )
{
out.println(count);
}
else request.getSession(false).setAttribute("count", new Integer(1));
%>
Hello!
</body></html>

(Select 1 correct option.)

A. It will print Hello!
B. It will print Hello and will set the count attribute in the session.
C. It will throw a NullPointerException at request time.
D. It will not compile.

I will choose C, but the answer is B.
Why?
I think it will give you an error when you type the html link because the doGet() didn't define.
Which of the given statements are correct regarding the following JSP page code?

<jsp:useBean id="mystring" class="java.lang.String" />
<jsp:setProperty name="mystring" property="*" />
<%=mystring%>

Assume that the request for this page contains a parameter mystring=hello.

A. It will print "".
B. It will print "hello"
C. It will not compile.
D. It will throw exception at runtime.

why choose A?
going into src will do the trick
I check servlet special yesterday before I post that. now I wrie a progrom to test it. You are right. HttpSessionActivationListener don't need to register in DD. Thank you to clear that.
These articles ref to servlet 2.3, now servlet 2.4

Originally posted by Mikalai Zaikin:

Also, refer these articles :

http://www.macromedia.com/support/jrun/ts/documents/tn18279.htm
http://e-docs.bea.com/wls/docs70/webapp/app_events.html

regards,
MZ


[ December 09, 2004: Message edited by: Romy Huang ]
*HttpSessionBindingListener* must not be registered in deployment descriptor, not *HttpSessionActivationListener*.


In HF servlet & JSP page 261 says this.
[ December 09, 2004: Message edited by: Romy Huang ]
You are right. There are serval thread for this. You can do a search.

here is one link:
Thread
if you want to support same function in both doPost() and doGet(), you can do both way.
1) in doGet(), call doPost() which has function logic.
or
2) in doPost(), call doGet() which has function logic.