This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes IDEs, Version Control and other tools and the fly likes Including Code From Another Source on a JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Including Code From Another Source on a JSP" Watch "Including Code From Another Source on a JSP" New topic
Author

Including Code From Another Source on a JSP

Greg Werner
Ranch Hand

Joined: May 07, 2009
Posts: 54
Hi all, just a simple question today.

When writing a simple tag (JSP 2.0 tag) is it strictly forbidden to use html tags?

As a further question, what if I had code which was repeated on like 100 different jsp pages that was ALL html tags. Would it be a gross violation to use simple tags.

I guess I ask this just because I could technically have all flavors of includes (.html, .jspf, .jsp, .tag, .tld) and I really do not want this kind of mixture on a individual jsp page. I would prefer a more homogenous solution.

Thanks.

-Greg
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Greg Werner wrote:Hi all, just a simple question today.

When writing a simple tag (JSP 2.0 tag) is it strictly forbidden to use html tags?

As a further question, what if I had code which was repeated on like 100 different jsp pages that was ALL html tags. Would it be a gross violation to use simple tags.

I guess I ask this just because I could technically have all flavors of includes (.html, .jspf, .jsp, .tag, .tld) and I really do not want this kind of mixture on a individual jsp page. I would prefer a more homogenous solution.

Thanks.

-Greg


You can put html code in a tag-file, of course.
If you have repeated code in 100 jsps you should put it in a tag file, why to have repited code? When you say simple tags are you meaning tag-files or SimpleTag?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

Greg Werner wrote:When writing a simple tag (JSP 2.0 tag) is it strictly forbidden to use html tags?
Where did you get that notion? The whole idea of tag files is to be able to easily create tags using markup. Besides, HTML tags aren't tags at all to a JSP engine. It's just meaningless template text.

As a further question, what if I had code which was repeated on like 100 different jsp pages that was ALL html tags. Would it be a gross violation to use simple tags.
Not at all.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Greg Werner
Ranch Hand

Joined: May 07, 2009
Posts: 54
I mean .tag files, for instance:

Like I put when I want to include it on a page,

I put when I want to use the tag

And my feedback.tag would be

So what I am trying to do in this case is write a div which belongs on a great number of pages in a .tag file.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

Go for it.
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Yes, of course you can do that. For example I use them for including code that goes always at the beginning and at the end of all the jsps, I have a tag
<mytags:addContent>

other tags and jsp content

</mytags:addContent>

and in that tag I have the tipical <body> <html> <head>, etc... and the tag closings but I have just one file.
Greg Werner
Ranch Hand

Joined: May 07, 2009
Posts: 54
Bear Bibeault wrote:
Greg Werner wrote:When writing a simple tag (JSP 2.0 tag) is it strictly forbidden to use html tags?
Where did you get that notion?


That is what I thought. I guess I am paying too much attention to the Eclipse 3.4.x warnings which complain anytime you put an html tag in a .tag file. And this is because Eclipse probably does not know what a .tag file is I am guessing? Ok this becomes an Eclipse issue. Thank you very much your answer.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

Yeah, IDE warnings are frequently more wrong than they are right.
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
I have seen Eclipse telling me that <body> tag is wrong because it didn't recognize it Just don't pay attention to the warnings in html-related code in Eclipse.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Eclipse will only complain about things like that if you have mis-matched tags, which can happen depending on how you're breaking up your content. Personally I don't really like breaking things up in a way that puts mis-matched (including missing) tags in a single file--it's far too easy to make a mistake that way, and it seems like it's nearly always avoidable.
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
David Newton wrote:Eclipse will only complain about things like that if you have mis-matched tags, which can happen depending on how you're breaking up your content. Personally I don't really like breaking things up in a way that puts mis-matched (including missing) tags in a single file--it's far too easy to make a mistake that way, and it seems like it's nearly always avoidable.


That's not compleatly true (or not in my case :P ) cause in my Eclipse, in this piece of code it's complaining about the </div>



In the <div> it says that is an unknown tag and a warning is shown, but in the </div> it directly says error (no explanation and red line under de sentence), which is strange. I don't care too much about this, if the code works is fine for me.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

As this has become an IDE discussion, this topic has been moved to the IDEs forum.
Xinshi Chen
Greenhorn

Joined: May 12, 2009
Posts: 1
OK.


free psp wallpapers
 
 
subject: Including Code From Another Source on a JSP
 
Similar Threads
body-content--JSP or...
are there any known bugs with struts html:hidden tag?
Struts without tags
Custom tag containing generated JSTL : not interpreted
To Hans: Classic Tag, Simple Tag and Tag files