Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Why the class can't handle the taglib correctly?

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone!
I have a jsp page.There have 
<%@ taglib uri="Simpletag.tld" prefix="lyo"%>
<html>
<head>
<title>hello</title>
</head>
<body>
<p>A Group Web Matrix</p><p>
<font color=red><I>
<lyo:simple/><I></font></p>
<ul>
<li><a href="simple.jsp?choice=jspbook">Java friend</a></li>
<li><a href="simple.jsp?choice=Aspbook">.NET friend</a></li>
<li><a href="simple.jsp?choice=PHPbook">CGI friend</a></li>
</ul>
I want to the web page display the infomation when a user click the ul<li>.But it doesn't do anything when I click the choice.My Java code is:
////////////////////////////Echo.java////////////////////////////////////
public class Echo extends BodyTagSupport{
public int doStartTag()throws JspException{
String choice;
JspWriter out=pageContext.getOut();
ServletRequest request=pageContext.getRequest();
choice=new String(request.getParameter("choice"));
try{
out.println("<h4>");
out.println("You should choose");
out.println("</h4>");
out.println("<h3>");
if(choice=="Jspbook")
out.print("you choice Jsp book,right?");
else if(choice=="Aspbook")
out.print("You choice Asp book?Don't you certain?");
else if(choice=="PHPbook")
out.print("You Known ,YOu should... ...");
else
out.print("sorry!there is Nothing...");
out.println("</h3>");
}catch(IOException e){
System.out.println(e.toString());
}
return SKIP_BODY;
}
}
Who can tell me why?Thank you! :roll:
 
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is your custom tag getting processed? To check, view the source of the HTML page in your browser to see if the custom tag is still there or not. If it's still in the page, then the tag isn't getting processed. If it is, then the tag is getting invoked but something is wrong with your tag handler. A couple of things spring to mind - you probably don't need to subclass BodyTagSupport (TagSupport will do) and you should always use .equals() to compare two strings.
HTH
Simon
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Simon Brown:
Is your custom tag getting processed? To check, view the source of the HTML page in your browser to see if the custom tag is still there or not. If it's still in the page, then the tag isn't getting processed. If it is, then the tag is getting invoked but something is wrong with your tag handler. A couple of things spring to mind - you probably don't need to subclass BodyTagSupport (TagSupport will do) and you should always use .equals() to compare two strings.
HTH
Simon


Thank you simon!I very love your book and I buy it that you writing usually!I have professional jsp taglib and I think it is very good for my study!In this topic,I change the "==" to "jspbook".equals("string") and it works well.Thank you again!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic