当我添加struts标签时,格式化将消失。我该怎么办?
这是我的代码:
<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>
这是它呈现的方式。问题是由于struts标签。我已经包含了struts-bootstrap jar。可能是什么错误?
答案 0 :(得分:5)
Struts2使用Themes从Tags生成HTML:选择不同的主题,输出中的HTML不同。
默认主题为 XHTML ,可生成<td>
,<label>
以及元素周围的其他内容。
通常,I recommend使用简单主题,几乎不会生成其他代码,而会使您的代码 as
<constant name="struts.ui.theme" value="simple" />
但是在你的情况下,既然你说你已经在你的项目中加入了Struts2-bootstrap-plugin,那么......只需使用它!您没有在代码中使用它...包括JAR是不够的,您需要将 bootstrap 主题设置为默认主题:
<constant name="struts.ui.theme" value="bootstrap" />
并声明struts-bootstrap taglib使用<sb:head/>
标记,如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>
然后删除您手动编写的所有HTML,并开始使用该插件。