📄 day11.txt
字号:
input jsp :
---> finish
==========================================================
16,修改perform方法:
package ec_port_web;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import delegates.ShoppingDelegate;
import exceptions.ManageException;
import exceptions.ServiceLocatorException;
import java.util.Collection;
public class ShipmentMgmAction extends Action {
public ActionForward perform(
ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse httpServletResponse) {
try{
ShoppingDelegate sd = new ShoppingDelegate();
Collection col = sd.getAllShipment();
request.getSession().
setAttribute( "ALL_SHIPMENT" , col );
return actionMapping.findForward( "success" );
}catch( ServiceLocatorException se ){
se.printStackTrace();
return actionMapping.findForward( "error" );
}
catch( ManageException me ){
me.printStackTrace();
return actionMapping.findForward( "error" );
}
}
}
==========================================================
17,为ShipmentMgmAction配置forward
1) when success
path : /shipmentMgm.jsp
name : success
2) when some exceptions be caught
path : /fail.jsp
name : error
==========================================================
18, 创建shipmentMgm.jsp
<%@ page contentType="text/html; charset=GBK"
import="java.util.*,dto.*"%>
<html>
<head>
<title>
shipmentMgm
</title>
</head>
<%
Collection col =
(Collection)session.getAttribute( "ALL_SHIPMENT" );
%>
<body bgcolor="#ffffff">
<p align=center>
<table width="600" border="0" cellspacing="1"
cellpadding="4" bgcolor="3399ff">
<tr>
<td colspan="5" align="center">
<font color="#ffffff" class="title">
订单管理</font>
</td>
</tr>
<tr>
<td bgcolor="#ececec">配送号</td>
<td bgcolor="#ececec">订单号</td>
<td bgcolor="#ececec">用户名</td>
<td bgcolor="#ececec">总价值</td>
<td bgcolor="#ececec">状态</td>
</tr>
<form action="modifyShipmentStatus.do" method="post">
<%
Iterator i = col.iterator();
while( i.hasNext() ){
ShipmentDTO ship = ( ShipmentDTO )i.next();
%>
<tr>
<td bgcolor="#ececec">
<input type="checkbox" name="shipment_id"
value='<%=ship.getId()%>'>
<%=ship.getId()%></td>
<td bgcolor="#ececec">
<a href="showOrderLine.do?ORDER_ID=<%=ship.getOrder()%>">
<%=ship.getOrder()%></a></td>
<td bgcolor="#ececec">
<a ref="showUserContact.do?USER_ID=<%=ship.getUserid()%>">
<%=ship.getUserid()%></a>
</td>
<td bgcolor="#ececec"><%=ship.getCost()%></td>
<td bgcolor="#ececec">
<%=ship.getStatus().getName()%>
</td>
</tr>
<%
}
%>
<input type="submit" name="status" value="prepared">
<input type="submit" name="status" value="shipped">
<input type="submit" name="status" value="received">
</form>
</table><br>
</body>
</html>
==========================================================
19 为showOrderLine.do创建Aciton
file --> new --> web --> Aciton
package : ec_port_web
Aciton : ShowOrderLineAction
---> next
Action path : showOrderLine.do
formbean name :
scope :
validate :
input jsp :
---> finish
==========================================================
package ec_port_web;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import java.util.Collection;
import delegates.ShoppingDelegate;
import exceptions.ManageException;
import exceptions.ServiceLocatorException;
public class ShowOrderLineAction extends Action {
public ActionForward perform(
ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse httpServletResponse) {
String id = (String)
request.getParameter( "ORDER_ID");
try{
ShoppingDelegate sd = new ShoppingDelegate();
Collection col = sd.getOrderlinesByOrderId(id);
request.setAttribute( "ORDER_LINES" ,col );
return actionMapping.findForward( "success" );
}catch( ServiceLocatorException se ){
se.printStackTrace();
return actionMapping.findForward( "error" );
}catch( ManageException me ){
me.printStackTrace();
return actionMapping.findForward( "error" );
}
}
}
==========================================================
20,为ShowOrderLineAction配置forward
1) when success
path : /showOrderLine.jsp
name : success
2) when some exception be caught
path : /fail.jsp
name : error
==========================================================
21, 创建showOrderLine.jsp
<%@ page contentType="text/html; charset=GBK" import="java.util.*,dto.*"%>
<html>
<head>
<title>
showOrderLine
</title>
</head>
<%
Collection col =
( Collection ) request.getAttribute( "ORDER_LINES" );
%>
<body bgcolor="#ffffff">
<p align=center>
<table width="600" border="0" cellspacing="1"
cellpadding="4" bgcolor="3399ff">
<tr>
<td colspan="3" align="center">
<font color="#ffffff" class="title">
订单详细信息</font>
</td>
</tr>
<tr>
<td bgcolor="#ececec">产品名称</td>
<td bgcolor="#ececec">购买数量</td>
<td bgcolor="#ececec">消费总值</td>
</tr>
<%
Iterator i = col.iterator();
while( i.hasNext() ){
OrderLine line = (OrderLine) i.next();
%>
<tr>
<td bgcolor="#ececec">
<%=line.getProduct().getName()%>
</td>
<td bgcolor="#ececec"><%=line.getAmount()%></td>
<td bgcolor="#ececec"><%=line.getCost()%></td>
</tr>
<%
}
%>
</table>
</body>
</html>
==========================================================
22,为shipmentMgm.jsp 中的 showUserContact.do 创建Action
file --> new --> web --> Aciton
package : ec_port_web
Aciton : ShowUserContactAction
---> next
Action path : showUserContact.do
formbean name :
scope :
validate :
input jsp :
---> finish
==========================================================
23,修改Perform方法:
package ec_port_web;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import delegates.UserMgmDelegate;
import javax.ejb.FinderException;
import exceptions.ServiceLocatorException;
import javax.ejb.CreateException;
import dto.ContactInfoDTO;
public class ShowUserContactAction extends Action {
public ActionForward perform(
ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse httpServletResponse) {
String userid = request.getParameter("USER_ID");
try{
UserMgmDelegate ud = new UserMgmDelegate();
ContactInfoDTO info = ud.getContactByUserId(userid);
request.setAttribute( "USER_CONTACT" , info );
return actionMapping.findForward( "success" );
}catch( ServiceLocatorException se ){
se.printStackTrace();
return actionMapping.findForward( "systemError" );
}catch( FinderException fe ){
fe.printStackTrace();
return actionMapping.findForward( "systemError" );
}catch( CreateException ce ){
ce.printStackTrace();
return actionMapping.findForward( "systemError" );
}
}
}
==========================================================
24,为ShowUserContactAction配置forward
1) when success
path : /showUserContact.jsp
name : success
2) when some exception be caught
path : /fail.jsp
name : systemError
==========================================================
25,创建showUserContact.jsp
<%@ page contentType="text/html; charset=GBK"
import = "dto.ContactInfoDTO "%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html>
<head>
<title>
modifyUserContact
</title>
</head>
<body bgcolor="#ffffff">
<%
ContactInfoDTO info = (ContactInfoDTO)
request.getAttribute( "USER_CONTACT" );
%>
<p align=center>
<table width="600" border="0" cellspacing="1"
cellpadding="4" bgcolor="3399ff">
<tr>
<td colspan="2" align="center">
<font color="#ffffff" class="title">
用户信息</font>
</td>
</tr>
<tr>
<td bgcolor="#ececec" width="22%"
align="center" height="11">
user name:
</td>
<td bgcolor="#FFFFFF" height="11">
<%=info.getUserid()%>
</td>
</tr>
<tr>
<td bgcolor="#ececec" width="22%"
align="center" height="11">
street1:
</td>
<td bgcolor="#FFFFFF" height="11">
<%=info.getStreet1()%>
</td>
</tr>
<tr>
<td bgcolor="#ececec" width="22%"
align="center" height="11">
street2:
</td>
<td bgcolor="#FFFFFF" height="11">
<%=info.getStreet2()%>
</td>
</tr>
<tr>
<td bgcolor="#ececec" width="22%"
align="center" height="11">
City:
</td>
<td bgcolor="#FFFFFF" height="11">
<%=info.getCity()%>
</td>
</tr>
<tr>
<td bgcolor="#ececec" width="22%"
align="center" height="11">
province:
</td>
<td bgcolor="#FFFFFF" height="11">
<%=info.getProvince()%>
</td>
</tr>
<tr>
<td bgcolor="#ececec" width="22%"
align="center" height="11">
country:</td>
<td bgcolor="#FFFFFF" height="11">
<%=info.getCountry()%>
</td>
</tr>
<tr>
<td bgcolor="#ececec" width="22%"
align="center" height="11">
zip:
</td>
<td bgcolor="#FFFFFF" height="11">
<%=info.getZip()%>
</td>
</tr>
<tr>
<td bgcolor="#ececec" width="22%"
align="center" height="11">
Email:
</td>
<td bgcolor="#FFFFFF" height="11">
<%=info.getEmail()%>
</td>
</tr>
<tr>
<td bgcolor="#ececec" width="22%"
align="center" height="11">
home phone:
</td>
<td bgcolor="#FFFFFF" height="11">
<%=info.getHomephone()%>
</td>
</tr>
<tr>
<td bgcolor="#ececec" width="22%"
align="center" height="11">
cellphone:
</td>
<td bgcolor="#FFFFFF" height="11">
<%=info.getCellphone()%>
</td>
</tr>
<tr>
<td bgcolor="#ececec" width="22%"
align="center" height="11">
office phone:</td>
<td bgcolor="#FFFFFF" height="11">
<%=info.getOfficephone()%>
</td>
</tr>
</table>
</body>
</html>
==========================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -