Search This Blog

Friday, February 10, 2006

How do you pass parameters to a servlet from JSP ?

I've come one query that how do youpass parameters to a servlet fromJSP.
and what kind of scope the JSP should have when we useforwardand backward button of the browser are used.

When you call a Servlet from a JSP by default JSP passes request and response objects to Servlet implicitly. So you canget all parameters in Servlet by

Explain statements string is immutable
String is a immutable means youcan't change the value of a String object once it is intialized. Sincewhen you create a String it creates a String Object in Heap or Stringpool and assigns the reference of this object to a String variable.

String str = new String("Java");

now Java is a object that iscreated in String pool. Once if you assign some String object to this"str" reference it is lost.

When you are creating or adding some string value this String for eg.

str =str.concat("Forum");

Here you are creating another String objectwith value "StringForum" in String Pool and you are assigning the "str"reference to this newly created object. Means you are loosing a oldstring

"Java" Since Strings are Immutable.

No comments: