Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Ashan Kaya   on Apr 04 In Java Category.

  
Question Answered By: Abbad Akhtar   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");

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
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: