之前的准备工作完成,现在算是正式进入struts项目的环节了,首先我们写一个发表留言的jsp页面。
    - 右键点击BBS项目, 选择 New > JSP,- 命名新文件为post. 点击Finish.- post.jsp将在右边的编辑器里打开了。
 
 
- 首先在编辑器中,将<title></title>中间的文字改成发表留言。
 
 
- 在文件顶部,添加以下2个taglib:
 <%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
 <%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
 bean tag为用户提供了若干tag,主要针对表单中form bean;html tag用来代替普通的html标签,达到简化操作的目的。
 
 
- 在<body>里面添加:
 <html:form action="post">
 
 </html:form>
 
    - 
    从IDE的Palette面板的HTML的分类里将Table拉入<html:form action="post">之间,设置rows 8,
    columns2。
 
 
- 在<td>之间添加数值
 
- <html:form action="post">
 <table border="1">
 <tbody>
 <tr>
 <td>名字</td>
 <td><html:text property="name" /></d>
 </tr>
 <tr>
 <td>邮件</td>
 <td><html:text property="email" /></td>
 </tr>
 <tr>
 <td>题目</td>
 <td><html:text property="subject" /> <html:submit value="发送"/><html:cancel value="重置"/></td>
 </tr>
 <tr>
 <td colspan="2">正文<br>
 <html:textarea cols="60" rows="8" property="content" />
 </td>
 </tr>
 <tr>
 <td>网站</td>
 <td><html:text property="url"/></td>
 </tr>
 <tr>
 <td>图标</td>
 <td>
 <html:select property="iconId">
 <logic:iterate id="icon" name="NewForm" property="icons">
 <option value="<bean:write name='icon' property='id'/>"><bean:write name="icon" property="name"/></option>
 </logic:iterate>
 </html:select>
 </td>
 </tr>
 <tr>
 <td>密码</td>
 <td><html:password property="password"/>(英数8文字内)</td>
 </tr>
 <tr>
 <td>字色</td>
 <td>
 <html:radio property="font" value="#800000"><font color="#800000">■</font></html:radio>
 <html:radio property="font" value="#DF0000"><font color="#DF0000">■</font></html:radio>
 <html:radio property="font" value="#008040"><font color="#008040">■</font></html:radio>
 <html:radio property="font" value="#0000FF"><font color="#0000FF">■</font></html:radio>
 <html:radio property="font" value="#C100C1"><font color="#C100C1">■</font></html:radio>
 <html:radio property="font" value="#FF80C0"><font color="#FF80C0">■</font></html:radio>
 <html:radio property="font" value="#FF8040"><font color="#FF8040">■</font></html:radio>
 <html:radio property="font" value="#000080"><font color="#000080">■</font></html:radio>
 </td>
 </tr>
 </tbody>
 </table>
 </html:form>
 </body>
 
 - 第一个JSP页面就完成了。
考虑到后面的测试,再创建一个result.jsp页面;当post成功/失败的话,通过result.jsp来查看结果
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>留言板</title>
    </head>
    <body>
        <h1><bean:write name="NewForm" property="result" /></h1>
    </body>
</html>