程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> 簡單的struts應用開發(5)

簡單的struts應用開發(5)

編輯:關於JAVA

第六步:建立JSP視圖頁面 (主要有兩個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>

建產一個轉向頁面 (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>

運行程序:

啟動tomcat

啟動IE 在地址欄中輸入 http://localhost:8080/mystruts

OK.....

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved