Rakesh Mehra

Ranch Hand
+ Follow
since Nov 20, 2007
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 Rakesh Mehra

Originally posted by Jesper Young:
A string literal is text enclosed in double quotes in your source code.
A String object is an object of type String.




Ok i too visualize same(as stated by u).But then

String s = new String("abcdef");.......(A) // creates a string object.
String s = "abcdef";....................(B) //string literal.

why is it said that both (A) and (B) create a new String object, with a
value of �abcdef �, and assign it to a reference variable s.
16 years ago

Originally posted by Ilja Preuss:
And your question is...?



Help me in understanding the below:
Assigning a reference does not create a copy of the source object denoted by the reference variable on the right-hand side. Reference assignment also does not copy the state of the source object to any object denoted by the reference variable on the left-hand side. It merely assigns the reference value to the variable on the right-hand side to the variable on the left-hand side, so that they denote the same object.
16 years ago

Originally posted by Ilja Preuss:
And your question is...?



I'm not able to understand the below:

Assigning a reference does not create a copy of the source object denoted by the reference variable on the right-hand side. Reference assignment also does not copy the state of the source object to any object denoted by the reference variable on the left-hand side. It merely assigns the reference value to the variable on the right-hand side to the variable on the left-hand side, so that they denote the same object.
16 years ago
What is the diference between a String Literal and String Object?
16 years ago
Request help in uderstanding the below highlighted

Copying references by assignment creates aliases. The following example recapitulates that discussion:

Pizza pizza1 = new Pizza("Hot&Spicy");
Pizza pizza2 = new Pizza("Sweet&Sour");

pizza2 = pizza1;

Variable pizza1 is a reference to a pizza that is hot and spicy, and pizza2 is a reference to a pizza which is sweet and sour. Assigning pizza1 to pizza2 means that pizza2 now references the same pizza as pizza1, that is, the hot and spicy one. After assignment these variables are aliases, and either one can be used to manipulate the hot and spicy Pizza object.

Assigning a reference does not create a copy of the source object denoted by the reference variable on the right-hand side. Reference assignment also does not copy the state of the source object to any object denoted by the reference variable on the left-hand side. It merely assigns the reference value to the variable on the right-hand side to the variable on the left-hand side, so that they denote the same object.

16 years ago

Originally posted by David O'Meara:


OK, ignore the method name since it is not important to your query. Also, the method is deprecated and therefore should be avoided anyway.

When you write a Servlet class and deploy it, you provide a mapping in the web.xml file like this:



The servlet-class gets assigned a servlet-name, and the servlet-name gets matched to a url-pattern. This allows a servlet-class to have multiple servlet-names and a servlet-name to have multiple url-patterns.

But...

When you assign a class to a servlet-name, there is only a single instance of the Class created, and all requests to any URL that matches the pattern for that name all get passed to the one single Servlet instance. If your servlet maintains state (which is a bad thing) then all of those requests will share that state.

And...

Since you can map the servlet-class to multiple names, each of which will create a servlet Instance, then referring to the class matches multiple names, as stated in the text you highlighted.




Everybody Thanks a lot ....

16 years ago

Originally posted by David O'Meara:


OK, ignore the method name since it is not important to your query. Also, the method is deprecated and therefore should be avoided anyway.

When you write a Servlet class and deploy it, you provide a mapping in the web.xml file like this:



The servlet-class gets assigned a servlet-name, and the servlet-name gets matched to a url-pattern. This allows a servlet-class to have multiple servlet-names and a servlet-name to have multiple url-patterns.

But...

When you assign a class to a servlet-name, there is only a single instance of the Class created, and all requests to any URL that matches the pattern for that name all get passed to the one single Servlet instance. If your servlet maintains state (which is a bad thing) then all of those requests will share that state.

And...

Since you can map the servlet-class to multiple names, each of which will create a servlet Instance, then referring to the class matches multiple names, as stated in the text you highlighted.





Thanks a lot everybody ,helping me understand .
16 years ago

Originally posted by David O'Meara:


OK, ignore the method name since it is not important to your query. Also, the method is deprecated and therefore should be avoided anyway.

When you write a Servlet class and deploy it, you provide a mapping in the web.xml file like this:



The servlet-class gets assigned a servlet-name, and the servlet-name gets matched to a url-pattern. This allows a servlet-class to have multiple servlet-names and a servlet-name to have multiple url-patterns.

But...

When you assign a class to a servlet-name, there is only a single instance of the Class created, and all requests to any URL that matches the pattern for that name all get passed to the one single Servlet instance. If your servlet maintains state (which is a bad thing) then all of those requests will share that state.

And...

Since you can map the servlet-class to multiple names, each of which will create a servlet Instance, then referring to the class matches multiple names, as stated in the text you highlighted.




Thanks a lot
16 years ago

Originally posted by Raghavan Muthu:
Howdy Rakesh Mehra,

David has clearly pointed out and i guess it helps. I think though its deprecated, it does NOT mean that it can be left without understanding.

But still what exactly you were NOT getting from the above pasted description?

As Ulf suggested, if you could let us know what you had thought on it, we could help you out in clearing the same.






I'm trying to ubderstand the below highlighted bold line:

Use getServlet() to get a particular servlet:

public Servlet ServletContext.getServlet(String name) throws ServletException
This method returns the servlet of the given name, or null if the servlet is not found. The specified name can be the servlet's registered name (such as "file") or its class name (such as "com.sun.server.webserver.FileServlet"). The server maintains one servlet instance per name, so getServlet("file") returns a different servlet instance than getServlet("com.sun.server.webserver.FileServlet").


As i felt "one servlet instance per registered name".




Help me to clear my understanding on Servlet instance. I visualize servlet instance as below:

Suppose i register a servlet (eg. aaa.class) using following in deployment descriptor:
<servlet-class>aaa.class</servlet-class>
<servlet-name>demo</servlet-name>

so is it like: demo = new aaa();


[ December 17, 2007: Message edited by: David O'Meara ]
16 years ago

Originally posted by David O'Meara:
Maybe I'm being a bit slow, but I don't understand your question and I am, as Ulf suggests, asking for more information on the source to get some context on your question. Repeating your question is no more helpful than me repeating my request for more information.



Chapter 11 of Java Servlet Programming

I'm reading a Chapter 11. Interservlet Communication which contains topic 11.1. Servlet Manipulation.i'm not able to uderstand it.
[ December 17, 2007: Message edited by: David O'Meara ]
16 years ago

Originally posted by David O'Meara:


Where is the quote from?



Help me in uderstanding below:

Use getServlet() to get a particular servlet:

public Servlet ServletContext.getServlet(String name) throws ServletException
This method returns the servlet of the given name, or null if the servlet is not found. The specified name can be the servlet's registered name (such as "file") or its class name (such as "com.sun.server.webserver.FileServlet"). The server maintains one servlet instance per name, so getServlet("file") returns a different servlet instance than getServlet("com.sun.server.webserver.FileServlet").
16 years ago

Originally posted by David O'Meara:


Where is the quote from?



Help me in uderstanding below:

Use getServlet() to get a particular servlet:

public Servlet ServletContext.getServlet(String name) throws ServletException
This method returns the servlet of the given name, or null if the servlet is not found. The specified name can be the servlet's registered name (such as "file") or its class name (such as "com.sun.server.webserver.FileServlet"). The server maintains one servlet instance per name, so getServlet("file") returns a different servlet instance than getServlet("com.sun.server.webserver.FileServlet").
16 years ago

Originally posted by Jesper Young:
Obviously the Java code that tries to make the connection does not have permission to connect to the database.

From where are you trying to connect to the database - from an applet? Note that applets have security restrictions; you can't create a network connection to any server from inside an applet.



STANDALONE servlet trying to access the local database.
But the point is when the same code tried on other system works well.

why so

Originally posted by David O'Meara:
Where is the quote from?



Use getServlet() to get a particular servlet:

public Servlet ServletContext.getServlet(String name) throws ServletException
This method returns the servlet of the given name, or null if the servlet is not found. The specified name can be the servlet's registered name (such as "file") or its class name (such as "com.sun.server.webserver.FileServlet").

The server maintains one servlet instance per name, so getServlet("file") returns a different servlet instance than getServlet("com.sun.server.webserver.FileServlet").

16 years ago
Help in understanding below highlighted in bold

Use getServlet() to get a particular servlet:

public Servlet ServletContext.getServlet(String name) throws ServletException
This method returns the servlet of the given name, or null if the servlet is not found. The specified name can be the servlet's registered name (such as "file") or its class name (such as "com.sun.server.webserver.FileServlet").

The server maintains one servlet instance per name, so getServlet("file") returns a different servlet instance than getServlet("com.sun.server.webserver.FileServlet")

16 years ago