📄 day04_2.txt
字号:
1,在首页上添加一个连接:
<html:link href="advinceMgm.jsp">managment</html:link>
==========================================================
为 adviceMgm.jsp 创建Filter ....
==========================================================
2,创建advinceMgm.jsp
<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="78%"
align="center" height="11">产品管理</td>
<td bgcolor="#FFFFFF" height="11">
<html:link href="productMgm.do">
[ 进入 ]</html:link>
</td>
</tr>
<tr>
<td bgcolor="#ececec" width="78%"
align="center" height="11">类别管理</td>
<td bgcolor="#FFFFFF" height=" ">
<html:link href="categoryMgm.do">
[ 进入 ]</html:link>
</td>
</tr>
<tr>
<td bgcolor="#ececec" width="78%"
align="center" height="11">订单管理</td>
<td bgcolor="#FFFFFF" height="11">
<html:link href="shipmentMgm.do">
[ 进入 ]</html:link>
</td>
</table>
==========================================================================================
file ---> Acton
package : ec_port_web
Action : CategoryMgmAction
path : /categoryMgm
=========================================================================================
实现 perform 方法:
package ec_port_web;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import java.util.Collection;
import javax.ejb.FinderException;
import exceptions.*;
import delegates.ProductMgmDelegate;
import javax.ejb.CreateException;
import java.util.Collection;
public class CategoryMgmAction extends Action {
public ActionForward perform(
ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse httpServletResponse) {
try{
ProductMgmDelegate pd = new ProductMgmDelegate();
Collection col = pd.getAllCategory();
request.getSession().
setAttribute( "ALL_CATEGORY" ,col );
return actionMapping.findForward( "success" );
}catch( ServiceLocatorException se ){
se.printStackTrace();
return actionMapping.findForward( "systemError" );
}
catch( CreateException ce ){
ce.printStackTrace();
return actionMapping.findForward( "systemError" );
}
catch( FinderException fe ){
fe.printStackTrace();
return actionMapping.findForward( "systemError" );
}
}
}
============================================================================================
为CategoryMgmAction 配置forword
1, path : /categoryMgm.jsp
name : success
2, path : /systemerror.html
name : fail
========================================================
==========================================================
新建categoryMgm.jsp
<%@ page contentType="text/html; charset=GBK"
import = "java.util.*,dto.*" %>
<html>
<head>
<title>
categoryMgm
</title>
<%
Collection col =
(Collection)session.getAttribute( "ALL_CATEGORY" );
%>
</head>
<body bgcolor="#ffffff">
<jsp:include page="header.jsp"/>
<%
if( col.size() == 0 ){
%>
<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" align="center">
现在没有任何类别</td>
</tr>
</table>
<%
}
else{
Iterator i = col.iterator();
%>
<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>
<%
while( i.hasNext() ){
CategoryDTO category =
(CategoryDTO)i.next();
%>
<form action="delmodCategory.do" method="post">
<tr>
<input type="hidden" name="id"
value='<%=category.getId()%>'>
<td bgcolor="#ececec">
<%=category.getName()%></td>
<td bgcolor="#ececec" >
<input type="submit" name="Modify" value="modify">
</td>
<td bgcolor="#ececec" >
<input type="submit" name="Delete"
value="delete"></td>
</tr>
</form>
<%
}
}
%>
</table>
<a href="newCategory.jsp">add a new Category</a>
</body>
</html>
==========================================================
新建 newCategory.jsp
form action="newCategory.do" method="post">
<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">类别名称</td>
<td bgcolor="#ececec">
<input type = "text" name="name"></td>
</tr>
<tr>
<td bgcolor="#ececec">详细描述</td>
<td bgcolor="#ececec">
<textarea name="desc"></textarea>
</td>
</tr>
<tr>
<td colspan=2 bgcolor="#ececec"
align="center">
<input type="submit" value="添加">
</td>
</tr>
</table>
==========================================================
为newCategory.jsp 创建FormBean:
file --> new --> web --> actionForm
填写
package : web_port_web
actionForm : ec_port_web.NewCatoryForm
--> next --> add from jsp --> newCategory.jsp --> next
formBean name : newCategoryForm
(注意:
actionForm : 对应<html:form>中的type
formbean name : 对应<html:form>中的name
)
b) 重写validate 和 reset 方法
c) 编译
===============================================
创建 NewCategoryAction
file --> new --> web --> Action
填写 package : ec_port_web
Action : NewCategoryAction
--> next
ActionPath : /newCategory
form bean name: newCategoryForm
scope : session
validate : true
input jsp : newCategory.jsp
=============================================
package ec_port_web;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import delegates.ProductMgmDelegate;
import exceptions.*;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
import dto.CategoryDTO;
import java.util.Collection;
public class NewCategoryAction extends Action {
public ActionForward perform(
ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse httpServletResponse) {
NewCategoryForm newCategoryForm =
(NewCategoryForm) actionForm;
try{
ProductMgmDelegate pd = new ProductMgmDelegate();
pd.createCategory( new CategoryDTO(
null,
newCategoryForm.getName(),
newCategoryForm.getDesc()));
Collection col = pd.getAllCategory();
request.getSession().
setAttribute( "ALL_CATEGORY",col);
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" );
}
}
}
=========================================================
为 NewCategoryAction 配置forword
1,
path : /categoryMgm.jsp
name : success
2,
path : /systemerror.html
name : fail.jsp
=========================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -