superwei

          導(dǎo)航

          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          統(tǒng)計(jì)

          常用鏈接

          留言簿(4)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          簡單的struts應(yīng)用開發(fā)(5)

          第六步:建立JSP視圖頁面 (主要有兩個(gè)jsp文件. 添加頁面. adduser.jsp 查看頁面 viewuser.jsp)

          adduser.jsp

          <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
          <%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
          <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
          <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
          <%@ page contentType="text/html; charset=gb2312" %>
          <html:html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
          <title>
          adduser
          </title>
          </head>
          <body>
          <h1> </h1>
          <p>
          <html:form action="/user1Action.do" method="POST">
          <html:hidden property="action"/>
          <br>
          部門:
          <html:select property="dep">
          <html:options collection="dep" property="id" labelProperty="name1"/>
          </html:select>
          <br>
          ID:
          <logic:equal name="userActionForm" property="action" scope="request" value="add">
          <html:text property="user_id"/>
          </logic:equal>
          <logic:equal name="userActionForm" property="action" scope="request" value="edit">
          <html:text property="user_id" readonly="true"/>
          </logic:equal>
          <br>
          名字:<html:text property="user_name"/>
          <br>
          電話:<html:text property="tel"/>
          <br>
          <html:submit property="submit" value="Submit"/><br>
          <html:reset value ="Reset"/>
          </html:form>
          </body>
          </html:html>

          viewuser.jsp

          <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
          <%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
          <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
          <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
          <%@ page contentType="text/html; charset=GBK" %>
          <html:html>
          <head>
          <title>
          viewuser
          </title>
          </head>
          <body>
          <div align="center"><a href="userAction.do?action=add">add </a></div>
          <table width="60%" border="1" align="center">
          <tr bgcolor="#CCCCCC">
          <td>ID</td>
          <td>user_name</td>
          <td>dep</td>
          <td>tel</td>
          <td>modify</td>
          <td>del</td>
          </tr>
          <logic:iterate name="rs" id="user" scope="request" type="java.util.HashMap">
          <tr>
          <td><bean:write name="user" property="user_id"/> </td>
          <td><bean:write name="user" property="user_name"/> </td>
          <td><bean:write name="user" property="dep_name"/> </td>
          <td><bean:write name="user" property="tel"/> </td>
          <td><a href="userAction.do?action=edit&key=<bean:write name="user" property="user_id"/>">modify</a></td>
          <td><a href="userAction.do?action=del&key=<bean:write name="user" property="user_id"/>">del</a></td>
          </tr>
          </logic:iterate>
          </table>
          </body>
          </html:html>

          建產(chǎn)一個(gè)轉(zhuǎn)向頁面 (index.jsp)
          <%@ page contentType="text/html; charset=gb2312" %>
          <html>
          <head>
          <title>Untitled Document</title>
          <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
          </head>

          <body>
          <% response.sendRedirect("userAction.do?action=view"); %>
          </body>
          </html>

          遞七步:建立struts配置文件 (WEB-INF/config-struts.xml)

          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
          <struts-config>
          <form-beans>
          <form-bean name="userActionForm" type="mystruts.userActionForm" />
          </form-beans>
          <action-mappings>
          <action type="mystruts.userAction" scope="request" path="/userAction">
          <forward name="view" path="/viewuser.jsp" />
          <forward name="add" path="/adduser.jsp" />
          <forward name="delview" path="/userAction.do?action=view" />
          </action>
          <action name="userActionForm" type="mystruts.user1Action" scope="request" path="/user1Action">
          <forward name="view" path="/userAction.do?action=view" />
          </action>
          </action-mappings>
          </struts-config>

          運(yùn)行程序:
          啟動(dòng)tomcat
          啟動(dòng)IE 在地址欄中輸入 http://localhost:8080/mystruts

          OK.....

          posted on 2005-10-31 10:33 小辭猬 閱讀(273) 評論(0)  編輯  收藏 所屬分類: JAVA

          主站蜘蛛池模板: 江北区| 綦江县| 南投市| 神木县| 玉林市| 卢氏县| 特克斯县| 马鞍山市| 兴业县| 陕西省| 东山县| 于都县| 涪陵区| 广元市| 金堂县| 临高县| 长顺县| 桂林市| 雅安市| 合肥市| 乌拉特前旗| 襄城县| 凤山市| 岑溪市| 盖州市| 克拉玛依市| 武宣县| 苏州市| 阿拉尔市| 来凤县| 广平县| 昂仁县| 灵璧县| 贡觉县| 泗阳县| 晋宁县| 华亭县| 彩票| 扎兰屯市| 夏津县| 海丰县|