简体   繁体   English

Spring MVC的标签库

[英]Tag Libraries for Spring MVC

I'm writing a web application using Spring MVC. 我正在使用Spring MVC编写Web应用程序。 Although Spring MVC comes with a couple of tag libraries, they are not rich as Struts' counterpart. 虽然Spring MVC附带了几个标记库,但它们并不像Struts那样丰富。 What I miss most is <html:xhtml> . 我最想念的是<html:xhtml>

Those of you using Spring MVC, what third-party tag libraries do you guys use? 那些使用Spring MVC的人,你们使用的是哪些第三方标签库?

Thanks! 谢谢!

Edit: More specifically, I would like to auto-generate the following using a custom tag. 编辑:更具体地说,我想使用自定义标记自动生成以下内容。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

If all you want to do is generate that fragment, then what's wrong with <jsp:include> , or a simple tagfile, eg 如果您只想生成该片段,那么<jsp:include>或简单的标记文件有什么问题,例如

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<jsp:doBody>
</html>

Stick that in /WEB-INF/tags/xhtml.tag , and you're done, eg 坚持在/WEB-INF/tags/xhtml.tag ,你完成了,例如

<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>

<tags:xhtml>
   // Rest of content in here
</tags:xhtml>

You might want to try the spring's form taglib 您可能想尝试spring的form taglib

"<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>" “<%@ taglib prefix =”form“uri =”http://www.springframework.org/tags/form“%>”

it is html 4.01 and XHTML1.0 compliant. 它符合html 4.01和XHTML1.0。

With HTML5's doctype being much more simple, all you need to have now for a doctype is <!doctype html> which is just as short, or shorter, than most tag libs, and also has much less overhead. HTML5的doctype要简单得多,现在你需要的所有文档类型都是<!doctype html> ,它与大多数标记库一样短或短,并且开销也少得多。

All you need now is: 你现在需要的只是:

<!doctype html>
<html>
</html>

The best solution, however, is still to put your basic boilerplate into an include file like @skaffman suggested. 然而,最好的解决方案仍然是将您的基本样板文件放入像@skaffman建议的包含文件中。 This lets you get the boilerplate nice and optimized and then you can keep using the same one and don't have to worry about it any more. 这可以让你获得漂亮和优化的样板,然后你可以继续使用相同的样板,而不必再担心它。 The HTML5Boilerplate project is a good place to start for that. HTML5Boilerplate项目是一个很好的起点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM