您的位置: 首页 > 技术文档 > 网络编程 > [J2EE]实战留言本(升级应用篇)
用http组件实现多引擎搜索功能 回到列表 利用ASP连接各种数据库
 [J2EE]实战留言本(升级应用篇)

作者:maxuan 时间: 2003-10-04 文档类型:原创 来自:蓝色理想

第 1 页 [J2EE]实战留言本 [1]
第 2 页 [J2EE] 实战留言本 [2]
第 3 页 [J2EE] 实战留言本 [3]
第 4 页 [J2EE] 实战留言本 [4]
第 5 页 [J2EE] 实战留言本 [5]
第 6 页 [J2EE] 实战留言本 [6]
第 7 页 [J2EE] 实战留言本[7]
第 8 页 [J2EE] 实战留言本 [8]
第 9 页 [J2EE] 实战留言本 [9]
第 10 页 [J2EE] 实战留言本[补遗]

由于在此篇教程中并没有涉及到国际化应用,应此我们并没有编写相应的资源文件!
struts-config.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="lyForm" type="guestbook.maxuan.action.LyForm" />
</form-beans>
<action-mappings>
<action path="/lyList"
type="guestbook.maxuan.action.LyListAction">
<forward name="success" path="/indexCnt.jsp" redirect="false" />
</action>
<action path="/saveLy" type="guestbook.maxuan.action.LySaveAction"
name="lyForm" input="/ly.jsp" 

scope="request">
<forward name="success" path="/index.jsp" redirect="true" />
</action>
<action path="/editLy" type="guestbook.maxuan.action.LyEditAction"
 name="lyForm" scope="request">
<forward name="success" path="/ly.jsp" redirect="false" />
</action>
</action-mappings>
<message-resources parameter="ApplicationResources"
key="org.apache.struts.action.MESSAGE" />
</struts-config>


以上,我们完成了此次教程应用的struts-config.xml的编写,我们看到使用struts console工具编写Struts-config.xml是多么的轻松容易,如果用纯文本编辑工具来写一个大型的struts配置文件,我想恐怕是一个噩梦!

在完成了配置后,我们开始写JSP页面,首先我们定义template,它是struts的模板,所有相同的部份都可以使用template!
template.jsp的源代码
<%@ taglib uri='/WEB-INF/struts-template.tld' prefix='template' %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>留言本教程范例</title>
</head>
<body bgcolor="#ffffff" leftmargin="0" topmargin="0"
marginwidth="0" marginheight="0">
<template:get name='header'/>
<template:get name='content'/>
<template:get name='footer'/>
</body>
</html>


接着完成首页index.jsp文件,它的模板使用template.jsp,定义了页首(header.htm),页尾(footer.htm),及内容显示(由/lyList.do映射到indexCnt.jsp)
index.jsp的源代码
<%@ taglib uri='/WEB-INF/struts-template.tld' prefix='template' %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<template:insert template='/template.jsp'>
<template:put name='header' content='/header.htm'/>
<template:put name='content' content='/lyList.do'/>
<template:put name='footer' content='/footer.htm'/>
</template:insert>


页首header.htm的代码(由于只是教程,我并没有进行页面美化工作,大家可以根据自己的喜爱自定义)
<table width="90%" height="50" border="0" align="center" 
cellpadding="0" cellspacing="0">
<tr>
<td align="center"><strong>留 言 本</strong></td>
</tr>
</table>


页尾footer.htm的源代码
<table width="90%" border="0" align="center" cellpadding="0" 
cellspacing="0">
<tr>
<td align="center">留言本教程范例 2003-9-21</td>
</tr>
</table>


留言内容显示indexCnt.jsp的源代码
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<jsp:useBean id="lyList" scope="session"
type="java.util.ArrayList"/>
<table width="90%" border="0" align="center" cellpadding="0"
 cellspacing="0">
<tr>
<td align="right"><html:link page="/editLy.do?action=Add">我要
留言</html:link> </td>
</tr>
</table>
<logic:iterate id="value" name="lyList"
type="guestbook.maxuan.ejb.entity.value.BookValue" 

indexId="index">
<table width="90%" border="0" align="center"
cellpadding="5" cellspacing="2">
<tr>
<td><font size="4"><b><bean:write
name="value" property="name"/></b></font><br>
Email:<a href='mailto:<bean:write
name="value" property="email"/>'><bean:write name="value" 

property="email"/></a>
| QQ:<bean:write name="value" property="qq"/> <br>
留言时间:<bean:write name="value" 

property="posttime"/><br><br>
<bean:write name="value" property="comment"/></td>
</tr>
<tr>
<td height="1"><hr size="1" noshade></td>
</tr>
</table>
</logic:iterate>


留言输入页面ly.jsp的源代码
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html>
<head>
<title>留言</title>
<meta http-equiv="Content-Type"
content="text/html; charset=gb2312">
</head>
<body>
<table width="70%" border="1" align="center" cellpadding="2"
cellspacing="2" 

bordercolor="#000000">
<html:form action="/saveLy">
<tr>
<td width="21%" height="20">姓名</td>
<td width="79%" height="20"><html:text property="name"
 size="20"/></td>
</tr>
<tr>
<td height="20">email</td>
<td height="20"><html:text property="email" size="20"/></td>
</tr>
<tr>
<td height="20">qq</td>
<td height="20"><html:text property="qq" size="20"/></td>
</tr>
<tr>
<td height="20">留言内容</td>
<td height="20"><html:textarea property="comment" rows="5"
cols="50"/></td>
</tr>
<tr align="center">
<td height="20" colspan="2"><html:submit>保存</html:submit>
<html:reset>重置</html:reset></td>
</tr>
</html:form>
</table>
</body>
</html>
最后效果如图:
此时我们的j2ee体系的留言本教程也就告于段落!
从这篇教程我们可以窥见j2ee多层体系结构的端倪,
本篇教程只是一个基石,在此之上,你可以灵活地搭建更大型的应用,
这才是我写此文的最终目的!
后记:幻想曲花了30多分钟的时间从经典论坛中将maxuan9的帖子整理到了文档区,
希望对那些想学J2EE和正在学J2EE的朋友一点启示、一点帮助!
 

出处:蓝色理想
责任编辑:蓝色

上一页 [J2EE] 实战留言本 [8] 下一页 [J2EE] 实战留言本[补遗]

◎进入论坛网络编程版块参加讨论

相关文章 更多相关链接
xml留言本
flash留言本梯度教程(附源)
制作WAP留言本[ASP教程]
Dreamweaver MX 2004打造留言本
flashinn.com 免费FLASH留言本
作者文章
[J2EE] 实战开发EJB
实战留言簿(EJB,Struts应用篇)
IIS6“_PATH_”问题解决小技巧
实战 J2EE 开发购物网站 经验篇
关键字搜索 常规搜索 推荐文档
热门搜索:CSS Fireworks 设计比赛 网页制作 web标准 用户体验 UE photoshop Dreamweaver Studio8 Flash 手绘 CG
站点最新 站点最新列表
周大福“敬•自然”设计大赛开启
国际体验设计大会7月将在京举行
中国国防科技信息中心标志征集
云计算如何让安全问题可控
云计算是多数企业唯一拥抱互联网的机会
阿里行云
云手机年终巨献,送礼标配299起
阿里巴巴CTO王坚的"云和互联网观"
1499元买真八核 云OS双蛋大促
首届COCO桌面手机主题设计大赛
栏目最新 栏目最新列表
浅谈JavaScript编程语言的编码规范
如何在illustrator中绘制台历
Ps简单绘制一个可爱的铅笔图标
数据同步算法研究
用ps作简单的作品展示页面
CSS定位机制之一:普通流
25个最佳最闪亮的Eclipse开发项目
Illustrator中制作针线缝制文字效果
Photoshop制作印刷凹凸字体
VS2010中创建自定义SQL Rule
>> 分页 首页 前页 后页 尾页 页次:9/101个记录/页 转到 页 共10个记录

蓝色理想版权申明:除部分特别声明不要转载,或者授权我站独家播发的文章外,大家可以自由转载我站点的原创文章,但原作者和来自我站的链接必须保留(非我站原创的,按照原来自一节,自行链接)。文章版权归我站和作者共有。

转载要求:转载之图片、文件,链接请不要盗链到本站,且不准打上各自站点的水印,亦不能抹去我站点水印。

特别注意:本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有,文章若有侵犯作者版权,请与我们联系,我们将立即删除修改。

您的评论
用户名:  口令:
说明:输入正确的用户名和密码才能参与评论。如果您不是本站会员,你可以注册 为本站会员。
注意:文章中的链接、内容等需要修改的错误,请用报告错误,以利文档及时修改。
不评分 1 2 3 4 5
注意:请不要在评论中含与内容无关的广告链接,违者封ID
请您注意:
·不良评论请用报告管理员,以利管理员及时删除。
·尊重网上道德,遵守中华人民共和国的各项有关法律法规
·承担一切因您的行为而直接或间接导致的民事或刑事法律责任
·本站评论管理人员有权保留或删除其管辖评论中的任意内容
·您在本站发表的作品,本站有权在网站内转载或引用
·参与本评论即表明您已经阅读并接受上述条款
推荐文档 | 打印文档 | 评论文档 | 报告错误  
专业书推荐 更多内容
网站可用性测试及优化指南
《写给大家看的色彩书1》
《跟我去香港》
众妙之门—网站UI 设计之道
《Flex 4.0 RIA开发宝典》
《赢在设计》
犀利开发—jQuery内核详解与实践
作品集 更多内容

杂⑦杂⑧ Gold NORMANA V2