Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Custom Tag problem in JSP  RSS feed

 
Firec Wang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I meet a problem which drive me mad for migrating my application from WAS to tomcat6.0/7.0.
I write a custom tag, it is very easy as: out.write("<font color='red'>"+v+"</font>");

when I try to put it in the JSP file as: <mytag:pager v="<%=request.getContextPath()%>/121" />. It can not work.
the error message is: org.apache.jasper.JasperException: /WEB-INF/jsp/demo/index.jsp(51,52) attribute for %>" is not properly terminated.

however if I change the way for my tag as:<mytag:pager v="/<%=request.getContextPath()%>/121" />. I can see the UI but not correctly, the JSP command does not work. It just print '//121' but the value should be '//MyTest/121'.

I tried several times with different way to use my tag, the result are:
1.<mytag:pager v="<%=request.getContextPath()%>" />. It can work correctly.
2.<mytag:pager v="/mytest/121" />. It can work correctly.
3.<mytag:pager v="<%=request.getContextPath()%>/121" />. It can not work correctly.
4.<mytag:pager v="/<%=request.getContextPath()%>/121" />. It can not work correctly.

It seems I can not use Jsp command & HTML content together.
How can I make this can be used? Because it works in WebSphere.


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is first of all, not Tomcat specific, so I've moved it to the JSP forum.

Secondly, welcome to the Ranch!

Thirdly, I see that you are still using scriptlets in your pages even though they have been discredited since the introduction of JSP 2.0 in 2002. Why is that?

When using scriptlet expressions, you cannot use a scriptlet expression as the partial part of a custom tag value. It must be the entire custom tag value.

The modern EL (Expression Language) which is what you should be using allows this. Your tag reference would then be: <mytag:pager v="${pageContext.request.contextPath}/121" />

And lastly, the HTML <font> tag is deprecated. Why are you using it?
 
Firec Wang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear.

I am migrating a very old project to a new one, but I am not planning to modify so much codes. I was trying to find some easy way to deal with this.
Thanks for your advice; it seems I have to change the code. I will discuss it with my team.

I used to use the '<font>' tag to do some test, thanks for reminder, I will change it to another way.

This is a very useful website to find answers. And I will keep on asking questions here.

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try <mytag:pager v="<%= request.getContextPath() + '/121' %>" />
 
Firec Wang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it works.

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool. Once again, is because when using old=fashioned scriptlet expressions, the expression must be the entire value.

Be sure to avoid scriptlets entirely in new pages.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!