問題描述
當我添加 struts 標簽時,格式消失了.我該怎么辦?
這是我的代碼:
<div class="panel-body" style="background-color:;"><div對齊=中心"><字體大小=3><s:form id="FormAddUser" name="FormAddUser"action="AddUser" method="post" class="form-horizo??ntal"><div class="row" align="center"><div class="col-sm-6"><div class="col-sm-4" align="right"><label>用戶 ID</label></div><s:textfield name="UserId" class="form-control"></s:textfield></div></div><br><div class="row" align="center"><div class="col-sm-6"><div class="col-sm-4" align="right"><標簽>名稱</標簽></div><s:textfield name="Name" class="form-control"></s:textfield></div></div><br><div class="row" align="center"><div class="col-sm-6"><div class="col-sm-4" align="right"><label>地址</label></div><s:textarea name="Address" class="form-control"></s:textarea></div></div><br><div class="row" align="center"><div class="col-sm-6"><div class="col-sm-4" align="right"><label>出生日期</label></div><s:textfield name="DOB" class="form-control" placeholder="dd/mm/yy"></s:textfield></div></div><br><div class="row" align="center"><div class="col-sm-6"><div class="col-sm-4" align="right"><label>密碼</label></div><s:password name="Password" class="form-control"></s:password></div></div><br><div class="row" align="center"><div class="col-sm-6"><div class="col-sm-4" align="right"><label>電子郵件 ID</label></div><s:textfield name="EmailId" class="form-control"placeholder="firstname.lastname@iiitb.org"></s:textfield></div></div><br><div class="row" align="center"><div class="col-sm-6"><div class="col-sm-4" align="right"><label>專業化</label></div><s:textfield name="Specialization" class="form-control"placeholder="CS/DS/NC/SE"></s:textfield></div></div><br><div class="row" align="center"><div class="col-sm-6"><div class="col-sm-4" align="right"><label>專業化</label></div><s:file name="Image" class="form-control" id="Image" key="Image"label="選擇要更改照片的文件" enctype="multipart/form-data"></s:file></div></div><br><div class="row" align="center"><div class="col-sm-7"><s:submit class="btn btn-primary" label="Add" onclick="check()"/><a href="admin.jsp" class="btn btn-primary btn-md"><跨度class="glyphicon glyphicon-repeat"></span>后退</a></div></div></s:form></字體></div></div></div>
這是它的渲染方式.問題是由于struts標簽.我已經包含了 struts-bootstrap jar.可能的錯誤是什么?
Struts2 使用 Themes 從標簽生成 HTML:一個不同的選擇的主題,輸出中的不同 HTML.
默認主題是 XHTML,它會在您的元素周圍生成 <td>
、<label>
和其他內容.p>
通常,我推薦使用simple主題,幾乎不會產生額外的代碼,而這將使您的代碼按原樣工作.把這個常量放到struts.xml中查看一下:
<constant name="struts.ui.theme" value="simple"/>
但在你的情況下,既然你說你已經包含了 Struts2-bootstrap-plugin 在你的項目中,然后......只需使用它!您沒有在代碼中使用它...包括 JAR 是不夠的,您需要將 bootstrap 主題設置為默認主題:
<constant name="struts.ui.theme" value="bootstrap"/>
并聲明 struts-bootstrap 標記庫以使用 <sb:head/>
標記,如 官方文檔:
<%@ taglib prefix="s" uri="/struts-tags" %><%@ taglib 前綴="sb" uri="/struts-bootstrap-tags" %><!DOCTYPE html><html lang="zh"><頭>...<!-- Le HTML5 shim,用于 IE6-8 對 HTML 元素的支持 --><!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]--><sb:head/></頭><身體>...</身體></html>
然后刪除您手動編寫的所有 HTML,并開始使用該插件.
When I add struts tags, the formatting disappears. What do I do?
This is my code:
<div class="panel-body" style="background-color:;">
<div align="center">
<font size=3> <s:form id="FormAddUser" name="FormAddUser"
action="AddUser" method="post" class="form-horizontal">
<div class="row" align="center">
<div class="col-sm-6">
<div class="col-sm-4" align="right">
<label>User ID</label>
</div>
<s:textfield name="UserId" class="form-control"></s:textfield>
</div>
</div>
<br>
<div class="row" align="center">
<div class="col-sm-6">
<div class="col-sm-4" align="right">
<label>Name</label>
</div>
<s:textfield name="Name" class="form-control"></s:textfield>
</div>
</div>
<br>
<div class="row" align="center">
<div class="col-sm-6">
<div class="col-sm-4" align="right">
<label>Address</label>
</div>
<s:textarea name="Address" class="form-control"></s:textarea>
</div>
</div>
<br>
<div class="row" align="center">
<div class="col-sm-6">
<div class="col-sm-4" align="right">
<label>Birth date</label>
</div>
<s:textfield name="DOB" class="form-control" placeholder="dd/mm/yy"></s:textfield>
</div>
</div>
<br>
<div class="row" align="center">
<div class="col-sm-6">
<div class="col-sm-4" align="right">
<label>Password</label>
</div>
<s:password name="Password" class="form-control"></s:password>
</div>
</div>
<br>
<div class="row" align="center">
<div class="col-sm-6">
<div class="col-sm-4" align="right">
<label>Email Id</label>
</div>
<s:textfield name="EmailId" class="form-control"
placeholder="firstname.lastname@iiitb.org"></s:textfield>
</div>
</div>
<br>
<div class="row" align="center">
<div class="col-sm-6">
<div class="col-sm-4" align="right">
<label>Specialization</label>
</div>
<s:textfield name="Specialization" class="form-control"
placeholder="CS/DS/NC/SE"></s:textfield>
</div>
</div>
<br>
<div class="row" align="center">
<div class="col-sm-6">
<div class="col-sm-4" align="right">
<label>Specialization</label>
</div>
<s:file name="Image" class="form-control" id="Image" key="Image"
label="Select a File to change photo" enctype="multipart/form-data"></s:file>
</div>
</div>
<br>
<div class="row" align="center">
<div class="col-sm-7">
<s:submit class="btn btn-primary" label="Add" onclick="check()" />
<a href="admin.jsp" class="btn btn-primary btn-md"> <span
class="glyphicon glyphicon-repeat"></span> Back
</a>
</div>
</div>
</s:form>
</font>
</div>
</div>
</div>
This is how it renders. The problem is because of the struts tags. I have included the struts-bootstrap jar. What could be the possible error?
Struts2 uses Themes to generate HTML from Tags: a different theme chosen, a different HTML in output.
The default theme is XHTML, that generates <td>
, <label>
and other stuff around your elements.
Usually, I recommend to use the simple theme, that generates almost no additional code, and that would make your code work as-is. Put this constant in struts.xml to check it out:
<constant name="struts.ui.theme" value="simple" />
But in your case, since you said you've included the Struts2-bootstrap-plugin in your project, then... simply use it ! You are NOT using it in your code... including the JAR is not enough, you need to set the bootstrap theme as the default one:
<constant name="struts.ui.theme" value="bootstrap" />
and declare the struts-bootstrap taglib to use the <sb:head/>
tag, as described in the official documentation:
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sb" uri="/struts-bootstrap-tags" %>
<!DOCTYPE html>
<html lang="en">
<head>
...
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<sb:head/>
</head>
<body>
...
</body>
</html>
Then remove all the HTML that you've written manually, and start using the plugin.
這篇關于為什么使用 Struts2-Boostrap-Plugin 會嚴重渲染 Bootstrap 的表單元素?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!