How do you pass parameters to a servlet from JSP?
What kind of scope the JSP should have when we use forwardand backward button of the browser are used.
1) 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
usingrequest.getParameter("text1");
Why "String" is immutable in Java?
2) 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.
Comments
Post a Comment