Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing parameter from JSP to tag handler

Status
Not open for further replies.

aas1611

Programmer
Dec 14, 2001
184
DE
I've been trying to pass a parameter from a JSP to a tag handler class.

I figured, the code in JSP to do this should be:

Code:
<%!
    String inputTM = request.getParameter("tradeMark");
%>
...
<p><learn:jspTM tradeMark="<%= inputTM %>" /> </p>

Problem 1:
When I run this JSP, an error message comes up saying:
Undefined variable or class name: request

Did I forget or should I include something?

Problem 2:
How can the tag handler class recognize this tradeMark variable?

FYI, I use Tomcat 3.3 and already put servlet.jar in my CLASSPATH.

Thanks for any hint!

Andre
 
Try changing this :

Code:
<%!
    String inputTM = request.getParameter("tradeMark");
%>

to this :

Code:
<%
    String inputTM = request.getParameter("tradeMark");
%>

The markup "<%!" is used for declaring a method.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Ok that works, or at least no error message... :)

But then I try to pass this variable to my tag handler class, which still doesn't seem work.

I called the jsp with the following command:

And in my tag handler:
Code:
private String tradeMark;

public void setTradeMark(String tradeMark) {
   this.tradeMark = tradeMark;
}
public String getTradeMark() { return tradeMark; }
...

This tradeMark should then be processed in another method (doAfterBody), but this variable seems empty (does not pass the input from JSP, which is "Java" in this case). The rtexprvalue for this tag has been set to "true".

The purpose of this program is to put the TM sign after every Java word.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top