Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Passing a parameter to jsp file

  Asked By: Ashan    Date: Apr 04    Category: Java    Views: 3189
  

How can I pass a paramater into a jsp file? The jsp file is being
called by a servlet.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Abbad Akhtar     Answered On: Apr 04

You can pass  an "attribute" between the
servlet and the JSP.

1) In your servlet, before redirecting to your JSP:
request.setAttribute("myID", "Any value passed");

2) In your JSP, to get the attribute:
String myString = (String) request.getAttribute("myID");

In general, you can pass any object, like this:

1) In your servlet, before redirecting to your JSP:
MyClass myObject = new MyClass(...);
request.setAttribute("myID2", myObject);

2) In your JSP, to get the attribute:
MyClass myObject = (MyClass) request.getAttribute("myID2");

 
Answer #2    Answered By: Cais Nguyen     Answered On: Apr 04

You can pass  by session or post/get

 
Didn't find what you were looking for? Find more on Passing a parameter to jsp file Or get search suggestion and latest updates.




Tagged: