html做个表格的步骤如下:
1、首先新建一个html,点击<body></body>中间,先填入表格内容;
2、内容根据需求来写即可,示例代码如下:
<table>
<p style="text-align:center ">功课表</p>
<tr>
<th>语文</th>
<td>7:00-7:40</td>
<td>7:50-8:30</td>
</tr>
<tr>
<th>数学</th>
<td>7:00-7:40</td>
<td>7:50-8:30</td>
</tr>
<tr>
<th>英文</th>
<td>7:00-7:40</td>
<td>7:50-8:30</td>
</tr>
</table>
3、然后在<head></head>中间输入样式表的样式;
4、样式也根据个人的需求来设置即可,设置单元格的宽度高度,合并单元格,位置,颜色等等,示例代码如下:
<style type="text/css">
body
{
width:340px
height :800px
}
table
{
border-collapse :collapse
}
th,td
{
width:100px
height:40px
border :1px solid black
font-size:12px
text-align :center
}
</style>
5、这里需要注意这个代码“table”的意义是将表格边框合并为单一的边框,将相邻变合并。
6、预览结果如下所示,一个简单的表格就制作出来了。
Html的表格用table来表示。下面,我们来看看HTML怎么插入表格吧。
table首先定义HTML表格,代码为<table></table>,如下图所示:
定义表格的行使用tr元素定义HTML表格的行,如下图所示:
定义单元格使用td元素定义单元格,如下图所示:
表格的边框然后用border定义表格的边框,如下图所示:
JSP将HTML的表单数据提交生成一个XML文件的方法:1、定义表单,封装id,firstName和lastName
<form:form modelAttribute="person">
<form:hidden path="id" />
<fieldset>
<div class="form-row">
<label for="firstName"><fmt:message key="person.form.firstName"/>:</label>
<span class="input"><form:input path="firstName" /></span>
</div>
<div class="form-row">
<label for="lastName"><fmt:message key="person.form.lastName"/>:</label>
<span class="input"><form:input path="lastName" /></span>
</div>
<div class="form-buttons">
<div class="button">
<input type="submit" id="save" name="_eventId_save" value="<fmt:message key="button.save"/>"/>
<input type="submit" name="_eventId_cancel" value="Cancel"/>
</div>
</div>
</fieldset>
</form:form>
2、提交到servlet后,调用构造xml的java方法:
try {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance()
DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
// root elements
Document doc = docBuilder.newDocument()
Element rootElement = doc.createElement("company")
doc.appendChild(rootElement)
// staff elements
Element staff = doc.createElement("Staff")
rootElement.appendChild(staff)
// set attribute to staff element
Attr attr = doc.createAttribute("id")
attr.setValue("1")
staff.setAttributeNode(attr)
// shorten way
// staff.setAttribute("id", "1")
// firstname elements
Element firstname = doc.createElement("firstname")
firstname.appendChild(doc.createTextNode("yong"))
staff.appendChild(firstname)
// lastname elements
Element lastname = doc.createElement("lastname")
lastname.appendChild(doc.createTextNode("mook kim"))
staff.appendChild(lastname)
// nickname elements
Element nickname = doc.createElement("nickname")
nickname.appendChild(doc.createTextNode("mkyong"))
staff.appendChild(nickname)
// salary elements
Element salary = doc.createElement("salary")
salary.appendChild(doc.createTextNode("100000"))
staff.appendChild(salary)
// write the content into xml file
TransformerFactory transformerFactory = TransformerFactory.newInstance()
Transformer transformer = transformerFactory.newTransformer()
DOMSource source = new DOMSource(doc)
StreamResult result = new StreamResult(new File("d:\\person.xml"));
transformer.transform(source, result)
System.out.println("File saved!")
} catch (ParserConfigurationException pce) {
pce.printStackTrace()
} catch (TransformerException tfe) {
tfe.printStackTrace()
}
3、构造完成:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<company>
<staff id="1">
<firstname>yong</firstname>
<lastname>mook kim</lastname>
<nickname>mkyong</nickname>
<salary>100000</salary>
</staff>
</company>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)