首 页 网络编程
网页制作 图形图象 操作系统 冲浪宝典
软件教学 认证考试

网络安全 网络办公 行业资讯 评测对比
您当前位置:站长天空 -> 软件教学-> 媒体工具
使用JSP + JAVABEAN + XML 开发的一个例子-JSP教程,Jsp/Servlet
作者:网友供稿 点击:19
推荐
西部数码-全国虚拟主机10强!20余项虚拟主机管理功能,全国领先!第6代双线路虚拟主机,南北访问畅通无阻!可在线rar解压,自动数据恢复设置虚拟目录等.免费赠送访问统计,企业邮局.Cn域名注册10元/年,自助建站480元起,免费试用7天,满意再付款!P4主机租用799元/月.月付免压金
站内搜索
文章页数:[1] 
本例子是参考了一些网站上有关jsp 对 xml 的操作的相关文档,又结合了一些个人的体会。例子涉及的内容是,开发的一个企业内部定餐系统后台管理端的部分代码,功能主要集中在对于餐馆基本信息的管理。

该例子本身开发的起因是我在原公司和同事们一个玩笑的一部分。特此也表达对那些一起共事的朋友们的想念。

例子本身是在tomcat4.01 平台下运行的b/s结构的程式。有关tomcat 的配置,这里不做说明。只讲解一下相关文件及文件夹的目录结构。

目录结构说明:
/tomcat/webapps/canyin/ -----主目录
/tomcat/webapps/canyin/jsp/ -----jsp 文件目录
/tomcat/webapps/canyin/jsp/admin/ -----实现后台管理的jsp 文件的存放目录
/tomcat/webapps/canyin/web-inf/classes/canyin/ ------javabean 文件的存放目录
/tomcat/webapps/canyin/data/ -----xml 文件存放目录
/tomcat/webapps/root/ -----tomcat 启动文件存放文件夹,只存放了index.html 文件

文件简单说明:
/tomcat/webapps/canyin/data/users.xml -----记录用户信息
/tomcat/webapps/canyin/data/restaurants.xml -----记录餐馆的基础信息


/tomcat/webapps/root/index.html -----首页,页面出现输入框,要求用户输入用户名,密码


/tomcat/webapps/canyin/jsp/loginjudge.jsp -----用户身份判断页面,根据用户名称和密码决定页面是转入后台管理端,还是前台客户端。本例子中,用户身份一旦确认为有管理权限,可以进入后台管理端,就直接跳到餐馆基本信息管理页面,简化说明的流程。
/tomcat/webapps/canyin/jsp/admin/admin_rest.jsp -----餐馆基本信息管理页面,管理餐馆的名称,电话,地址等信息

/tomcat/webapps/canyin/web-inf/classes/canyin/checksessionbean.class ----- 后台管理端检测标志用户身份的session 的值,如果不是管理员的话,跳回登陆页面。
/tomcat/webapps/canyin/web-inf/classes/canyin/connxmlbean.class -----连接xml 文件
/tomcat/webapps/canyin/web-inf/classes/canyin/writexmlbean.class -----写入xml文件

文件详细介绍及附带代码说明。

/tomcat/webapps/canyin/data/users.xml

代码:
<?xml version="1.0" encoding="utf-8" ?>

- <users>
<user name="joard" password="joard" roles="admin" />
<user name="joard01" password="joard01" roles="user" />
<user name="joard02" password="joard02" roles="user" />
</users>

说明:字段含义是用户名,密码以及用户的身份

/tomcat/webapps/canyin/data/restaurants.xml

代码:
<?xml version="1.0" encoding="utf-8" ?>
- <restaurants num="10">
- <restaurant id="1">
<name>上海亭快餐店</name>
<phone>021-76546726</phone>
<address>百老汇广场b座</address>
</restaurant>
- <restaurant id="8">
<name>香格里拉大饭店</name>
<phone>021-2312134</phone>
<address>南京路1023号</address>
</restaurant>
</restaurants>
说明:<num>属性是记录在restaurants.xml 文件中总共有过多少条记录,每新增一条,无论以后删除是否,该值都会增加1,就好象数据库中习惯使用的自动增加1的id 项。用来给新增的 <restaurant>的属性<id>赋一个唯一的值。其它的字段意思比较明显。
/tomcat/webapps/root/index.html (单纯的html代码)

代码:
<html>
<head>
<title>oddworld 餐饮系统</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
</head>

<body onload="javascript:dataform.username.focus()">
<div align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="22">
<tr>
<td width="1"><img src="images/top_r1.gif" width="62" height="22"></td>
<td width=150 align="center"> 餐饮系统登录 </td>
<td><img src="images/top_r2.gif" width="294" height="22"></td>
</tr>
</table>
<br>
<br>
<table width="300" border="0" cellspacing="1" cellpadding="0" >
<tr>
<td height="200" valign="top" align="center">
<p align="center">
<table width="100%" border="0" cellspacing="1" cellpadding="5" bgcolor=#999999 class=a9px>
<tr>
<td bgcolor="#efefef">餐饮系统登录</td>
</tr>
<tr>
<td bgcolor="#ffffff" valign="top" align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<form name=dataform method=post action=canyin/jsp/loginjudge.jsp>
<tr>
<td width="100"><b>登录名:</b></td>
<td>
<input maxlength=16
name="username" class=stedit value="joard">
</td>
</tr>
<tr>
<td width="100"><b>密码:</b></td>
<td>
<input class=stedit maxlength=16
name="userpass" type=password value="oddworld">
</td>
</tr>
</form>
</table>
<br>
<table border=0 cellpadding=0 cellspacing=0>
<tbody>
<tr>
<td>
<input class=stbtm name=update onclick="javascript:if (checkform()==false);" type=button value="登 录">
</td>
<td> </td>
<td>
<input class=stbtm name=submit onclick="javascript:window.location.href=index.asp?myjoke=1;" type=button value="修改密码">
</td>
<td> </td>
</tr>
</tbody>
</table>
<br>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
</html>
<script language=javascript>
<!--
function checkform()
{
var checkblank = /^(\s*|(\ )|(\.))*$/;
if (checkblank.test(dataform.username.value))
{
alert("登录名不能为空!");
return false;
}

if (checkblank.test(dataform.userpass.value))
{
alert("密码不能为空!");
return false;
}


window.dataform.submit();

}
-->

</script>

说明:把用户名称和用户密码提交到/tomcat/webapps/canyin/jsp/loginjudge.jsp

/tomcat/webapps/canyin/web-inf/classes/canyin/checksessionbean.class (代码是相应的java 文件)

package canyin;

import javax.servlet.http.httpsession;
import javax.servlet.http.httpservletrequest;

public class checksessionbean {

private boolean bolcheckpass=false;
private httpservletrequest request = null;

public boolean checksessionbean(httpservletrequest request,string strsessionname,string strcheckvalue){
public boolean checksessionbean(httpservletrequest request){
httpsession session = request.getsession(false);
return(bolcheckpass);

if (strsessionname==null || strcheckvalue==null){
return(bolcheckpass);
}else{
if (session!=null && session.getvalue(strsessionname)!=null){
bolcheckpass=session.getvalue(strsessionname).equals(strcheckvalue);
}

return(bolcheckpass);
}
}
}

说明:检验参数传入的session 名称的数值和参数传入的字段的数值是否相等。

/tomcat/webapps/canyin/web-inf/classes/canyin/connxmlbean.class

代码:
package canyin;

import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.domsource;
import javax.xml.transform.stream.streamresult;
import org.w3c.dom.*;

public class connxmlbean {

private documentbuilderfactory factory=null;
private documentbuilder builder=null;
private document doc=null;

public connxmlbean(){}

public string connxml(string xmlfilename){

string strexc="";

try{
factory = documentbuilderfactory.newinstance();
builder=factory.newdocumentbuilder();
doc=builder.parse(xmlfilename);
doc.normalize();
}catch(exception e){
strexc=e.tostring();
}

return(strexc);
}

public document getxmldoc(){
return(doc);
}
}

说明:打开一个指定xml 文件

/tomcat/webapps/canyin/web-inf/classes/canyin/writexmlbean.class

代码:
package canyin;

import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.domsource;
import javax.xml.transform.stream.streamresult;
import java.io.file;
import org.w3c.dom.*;

public class writexmlbean {

public writexmlbean(){}

public string writexml(document doc,string xmlfilename){

string strexc="";

try{
transformerfactory tfactory = transformerfactory.newinstance();
transformer transformer = tfactory.newtransformer();

domsource source = new domsource(doc);

streamresult result = new streamresult(new file(xmlfilename));

transformer.transform(source,result);
}catch(exception e){
strexc=e.tostring();
}

return(strexc);
}

}

说明:写入dom 的内容到一个指定的xml 文件。

/tomcat/webapps/canyin/jsp/loginjudge.jsp

代码:
<%-- oddworld 餐饮管理系统(简体中文版) 2002年12月1日
copy right by joard ast

loginjudge.jsp 功能:用户身份校验,根据 /data/user.xml 文件内标示的用户不同的身份
决定转入后台管理页面,还是客户点菜页面。
--%>

<%@ page contenttype="text/html;charset=gb2312" %>
<%@ page language="java" import="javax.xml.parsers.*" %>
<%@ page import="org.w3c.dom.*" %>
<%@ page import="canyin.*" %>

<jsp:usebean id="xmlbean" class="canyin.connxmlbean" scope="page" />

<%
session.setmaxinactiveinterval(1800);


document doc;
nodelist users;
string strexc="";
string strusername,strpassword;

strusername=(string)request.getparameter("username");
strpassword=(string)request.getparameter("userpass");

//校验数据是否为空
if (strusername=="" || strpassword=="" ){
out.println("<script language=javascript>");
out.println("alert(用户名或密码有空值!);");
out.println("window.location.href=/index.html;");
out.println("</script>");
return;
}

xmlbean.connxml("webapps/canyin/data/users.xml");
doc=xmlbean.getxmldoc();

try{
users =doc.getelementsbytagname("user");

for (int i=0;i<users.getlength();i++){
element user=(element) users.item(i);

string stratrnamevalue=user.getattributenode("name").getnodevalue();
string stratrpasswordvalue=user.getattributenode("password").getnodevalue();
string stratrrolevalue=user.getattributenode("roles").getnodevalue();



if (stratrnamevalue.equals(strusername) && stratrpasswordvalue.equals(strpassword)){

if (stratrrolevalue.equals("admin")){
out.println("<script language=javascript>");
out.println("alert(欢迎管理员登陆系统!);");
out.println("</script>");

//设置标示用户身份的 session(sesuserrole) ,管理员身份为 admin
session.setattribute("sesuserrole","admin");

//跳转到管理页面
response.sendredirect("admin/admin_rest.jsp");
return;

}else{
//设置标示用户身份的 session(sesuserrole) ,管理员身份为 user
session.setattribute("sesuserrole","user");

//跳转到普通用户页面
response.sendredirect("index.jsp");
return;
}

}else{
out.println("<script language=javascript>");
out.println("alert(用户名或密码错误!);");
out.println("history.go(-1);");
out.println("</script>");
return;
}

}
}catch(exception e){
strexc=e.tostring();
}
%>
说明:.......

/tomcat/webapps/canyin/jsp/admin/admin_rest.jsp

代码:
<%-- oddworld 餐饮管理系统(简体中文版) 2002年12月1日
copy right by joard ast

admin_rest.jsp 功能:后台管理页面,餐馆管理页面。
--%>

<%@ page contenttype="text/html;charset=gb2312" %>
<%@ page language="java" import="javax.xml.parsers.*" %>
<%@ page import="javax.xml.transform.*" %>
<%@ page import="org.w3c.dom.*" %>
<%@ page import="canyin.*" %>

<%@ include file="../../include/sys_dialog.jsp" %>

<jsp:usebean id="checksessionbean" class="canyin.checksessionbean" scope="page" />
<jsp:usebean id="xmlbean" class="canyin.connxmlbean" scope="page" />
<jsp:usebean id="writexmlbean" class="canyin.writexmlbean" scope="page" />

<%//校验可户身份,判断是不是管理员
if(!checksessionbean.checksessionbean(request,"sesuserrole","admin")){
out.print(showdialog("您没有管理的权限!","/index.html"));
return;
}

//从餐馆资料文件 rest.xml 中得到相关数据
document doc;
nodelist restaurants;

string stract;
int intid=0;
string stroperation="show";

//接受外部传入的参数
stract=(string)request.getparameter("act");

xmlbean.connxml("webapps/canyin/data/restaurants.xml");
doc=xmlbean.getxmldoc();
restaurants =doc.getelementsbytagname("restaurant");

//根据外部传入的参数来决定对 restaurant.xml 文件的操作
if (stract!=null){
if(stract.equals("addnewdo")){

string strname;
string strphone;
string straddress;
text textseg;

strname=(string)request.getparameter("name").trim();
strphone=(string)request.getparameter("phone").trim();
straddress=(string)request.getparameter("address").trim();

//数据校验
if(strname==null){
out.print(showdialog("餐馆名称不能为空!"));
return;
}
if(strphone==null){
out.print(showdialog("餐馆电话不能为空!"));
return;
}
/*if(straddress==null){
out.print(showdialog("餐馆地址不能为空!"));
return;
}*/

//校验数据的唯一性
for(int i=0;i<restaurants.getlength();i++){
element restaurant=(element) restaurants.item(i);
if(((string)restaurant.getelementsbytagname("name").item(0).getfirstchild().getnodevalue()).equals(strname)){
out.print(showdialog("餐馆名称重复!"));
return;
}else{
if(((string)restaurant.getelementsbytagname("name").item(0).getfirstchild().getnodevalue()).equals(strphone)){
out.print(showdialog("餐馆电话重复!"));
return;
}
}

}



//得到已有的记录数,给新增的餐馆记录设定唯一的递增的id 属性
int intnum=0;
element restnum=(element)doc.getelementsbytagname("restaurants").item(0);
intnum=integer.parseint(restnum.getattributenode("num").getnodevalue());

intnum+=1;

//为restaurants的属性num 的数值加1
restnum.getattributenode("num").setnodevalue(string.valueof(intnum));

//新增节点
element newrestaurant=doc.createelement("restaurant");

attr newarrid=doc.createattribute("id");
//attribute newarrid = new attribute("id",string.valueof(intnum));
textseg=doc.createtextnode(string.valueof(intnum));
newarrid.setvalue(string.valueof(intnum));
newrestaurant.setattributenode(newarrid);

element newname=doc.createelement("name");
textseg=doc.createtextnode(strname);
newname.appendchild(textseg);
newrestaurant.appendchild(newname);

element newphone=doc.createelement("phone");
textseg=doc.createtextnode(strphone);
newphone.appendchild(textseg);
newrestaurant.appendchild(newphone);

element newaddress=doc.createelement("address");
textseg=doc.createtextnode(straddress);
newaddress.appendchild(textseg);
newrestaurant.appendchild(newaddress);

doc.getdocumentelement().appendchild(newrestaurant);

//调用bean 写入相应的xml文件
writexmlbean.writexml(doc,"webapps/canyin/data/restaurants.xml");

response.sendredirect(request.getrequesturi());
return;
}
if(stract.equals("modido")){
string strname;
string strphone;
string straddress;
text textseg;
int modiid;
//记录要修改的记录是item(i)的哪一项
int inti=0;

strname=(string)request.getparameter("name").trim();
strphone=(string)request.getparameter("phone").trim();
straddress=(string)request.getparameter("address").trim();
modiid=integer.parseint(request.getparameter("recordid").trim());

//数据校验
if(strname==null){
out.print(showdialog("餐馆名称不能为空!"));
return;
}
if(strphone==null){
out.print(showdialog("餐馆电话不能为空!"));
return;
}
if(modiid==0){
out.print(showdialog("你要修改餐馆的记录不存在!"));
return;
}
/*if(straddress==null){
out.print(showdialog("餐馆地址不能为空!"));
return;
}*/

//标志显示记录存在
boolean recordexist=false;

//校验数据的唯一性
for(int i=0;i<restaurants.getlength();i++){
element restaurant=(element) restaurants.item(i);

if(integer.parseint(restaurant.getattributenode("id").getnodevalue())==modiid){
recordexist=true;
inti=i;

}

if(((string)restaurant.getelementsbytagname("name").item(0).getfirstchild().getnodevalue()).equals(strname) && integer.parseint(restaurant.getattributenode("id").getnodevalue())!=modiid ){
out.print(showdialog("餐馆名称重复!"));
return;
}else{
if(((string)restaurant.getelementsbytagname("name").item(0).getfirstchild().getnodevalue()).equals(strphone) && integer.parseint(restaurant.getattributenode("id").getnodevalue())!=modiid ){
out.print(showdialog("餐馆电话重复!"));
return;
}
}

}



if(!recordexist){
out.print(showdialog("你要修改餐馆的记录不存在!"));
return;
}else{
//进行记录更改的操作
try{
element modirestaurant=(element) restaurants.item(inti);
modirestaurant.getelementsbytagname("name").item(0).getfirstchild().setnodevalue(strname);
modirestaurant.getelementsbytagname("phone").item(0).getfirstchild().setnodevalue(strphone);
modirestaurant.getelementsbytagname("address").item(0).getfirstchild().setnodevalue(straddress);

//调用bean 写入相应的xml文件
writexmlbean.writexml(doc,"webapps/canyin/data/restaurants.xml");

response.sendredirect(request.getrequesturi());
return;

}catch(exception e){}
}
}
//进行删除操作
if(stract.equals("del")){
int delid;
//记录要修改的记录是item(i)的哪一项
int inti=0;

delid=integer.parseint(request.getparameter("recordid").trim());

if(delid==0){
out.print(showdialog("你要修改餐馆的记录不存在!"));
return;
}

file://标志显示记录存在
boolean recordexist=false;

//校验数据的唯一性
for(int i=0;i<restaurants.getlength();i++){
element restaurant=(element) restaurants.item(i);

if(integer.parseint(restaurant.getattributenode("id").getnodevalue())==delid){
recordexist=true;
inti=i;

}
}

if(!recordexist){
out.print(showdialog("你要删除餐馆的记录不存在!"));
return;
}else{
//进行记录删除的操作
try{
node delnode=(node)restaurants.item(inti);

doc.getelementsbytagname("restaurants").item(0).removechild(delnode);

//调用bean 写入相应的xml文件
writexmlbean.writexml(doc,"webapps/canyin/data/restaurants.xml");

response.sendredirect(request.getrequesturi());
return;

}catch(exception e){}
}

}
}

//由外部传入参数决定页面相应的处理状态
if (stract==null){
stroperation="show";
}else{
if (stract.equals("modi")){
stroperation="modi";
intid=integer.parseint(request.getparameter("recordid"));
}else{
if(stract.equals("addnew")){
stroperation="addnew";
}else{
stroperation="show";
}
}
}


//如果为空记录,则变更页面状态为“新增”
if (restaurants.getlength()==0){
stroperation="addnew";
}
%>

<html>
<head>
<title>oddworld 餐饮系统</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" href="../../include/itsp.css" type="text/css">
</head>

<body >
<div align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="22">
<tr>
<td width="1"><img src="../../images/top_r1.gif" width="62" height="22"></td>
<td width=150 align="center"> 餐饮系统管理--餐馆管理</td>
<td><img src="../../images/top_r2.gif" width="294" height="22"></td>
<td width=100 align="center"><a href="/index.html">[ 退出系统 ]</a></td>
</tr>
</table>
<br>
<br>
<table bgcolor="#999999" align=center border=0 cellpadding=1 cellspacing=1
width="90%">
<tbody>
<tr bgcolor="#efefef" align="center" valign="middle">
<td class=tttable height=30 width="20"> </td>
<td class=tttable height=30 width="0">餐馆名称</td>
<td class=tttable height=30 width="0">餐馆电话</td>
<td class=tttable height=30 width="0">
<div align="center">餐馆地址</div>
</td>
<td class=tttable height=30 width="30">
<div align="center">修改</div>
</td>
<td class=tttable height=30 width="30">
<div align="center">删除</div>
</td>
</tr>
<%
for(int i=0;i<restaurants.getlength();i++)
{
element restaurant=(element) restaurants.item(i);

if (stroperation=="modi" && integer.parseint(restaurant.getattributenode("id").getnodevalue())==intid){
%>
<%//显示修改的格式%>
<tr align="center" bgcolor="#ffffff" valign="middle">
<form name=dataform action="<%=request.getrequesturi()%>?act=modido" method="post" onsubmit=return checkform(this); >
<td class=tdsmall height=25 width="20">
<input type="hidden" name="recordid" value="<%=restaurant.getattributenode("id").getnodevalue()%>">
<%=(i+1)%></td>
<td class=tdsmall height=25>
<input name="name" class=stedit
style="height: 22px; width: 150px" value="<%if(restaurant.getelementsbytagname("name").item(0).haschildnodes()){
out.print(restaurant.getelementsbytagname("name").item(0).getfirstchild().getnodevalue());

}%>
" maxlength="40" >
</td>
<td class=tdsmall height=25>
<input name="phone" class=stedit
style="height: 22px; width: 100px" value="<%if(restaurant.getelementsbytagname("phone").item(0).haschildnodes()){
out.print(restaurant.getelementsbytagname("phone").item(0).getfirstchild().getnodevalue());

}%>" maxlength="20" >
</td>
<td class=tdsmall height=25>
<input name="address" class=stedit
style="height: 22px; width: 200px" value="<%

if(restaurant.getelementsbytagname("address").item(0).haschildnodes()){
out.print(restaurant.getelementsbytagname("address").item(0).getfirstchild().getnodevalue());

}%>" maxlength="100" >
</td>
<td class=tdsmall height=25 width="25"><a href="javascript:if (checkform()==false);"><img border=0
height=15 src="../../images/editok.gif" width=15></a></td>
<td class=tdsmall height=25 width="25"> </td>
</form>
</tr>
<% }else{
//显示正常的格式 %>
<tr align="center" bgcolor="#ffffff" valign="middle">
<td class=tdsmall height=25 width="20"><%=(i+1)%></td>
<td class=tdsmall height=25 width="0"><%if(restaurant.getelementsbytagname("name").item(0).haschildnodes()){
out.print(restaurant.getelementsbytagname("name").item(0).getfirstchild().getnodevalue());

}%>
</td>
<td class=tdsmall height=25 width="0"><%if(restaurant.getelementsbytagname("phone").item(0).haschildnodes()){
out.print(restaurant.getelementsbytagname("phone").item(0).getfirstchild().getnodevalue());

}%></td>
<td class=tdsmall height=25 width="0">
<%
if(restaurant.getelementsbytagname("address").item(0).haschildnodes()){
out.print(restaurant.getelementsbytagname("address").item(0).getfirstchild().getnodevalue());

}%>
</td>
<td class=tdsmall height=25 width="30"><a href="<%=request.getrequesturi()%>?act=modi&recordid=<%=restaurant.getattributenode("id").getnodevalue()%>"><img border=0
height=15 src="../../images/edit.gif" width=15></a></td>
<td class=tdsmall height=25 width="30"><img border=0
height=15
onclick="javascript:if(confirm(您是否确定删除本记录,删除后将导至记录无法使用?)){window.location.href=<%=request.getrequesturi()%>?act=del&recordid=<%=restaurant.getattributenode("id").getnodevalue()%>;}"
src="../../images/delete.gif" style="cursor: hand" width=15> </td>
</tr>
<% }
}%>
<% if (stroperation=="addnew"){
//显示新增的格式%>
<tr align="center" bgcolor="#ffffff" valign="middle">
<form name=dataform2 action="<%=request.getrequesturi()%>?act=addnewdo" method="post" onsubmit=return checkform2(this); >
<td class=tdsmall height=25 width="20"></td>
<td class=tdsmall height=25>
<input name="name" class=stedit
style="height: 22px; width: 150px" value="" maxlength="40" >
</td>
<td class=tdsmall height=25>
<input name="phone" class=stedit
style="height: 22px; width: 100px" value="" maxlength="20" >
</td>
<td class=tdsmall height=25>
<input name="address" class=stedit
style="height: 22px; width: 200px" value="" maxlength="100" >
</td>
<td class=tdsmall height=25 width="25"><a href="javascript:if (checkform2()==false);"><img border=0
height=15 src="../../images/editok.gif" width=15></a></td>
<td class=tdsmall height=25 width="25"> </td>
</form>
</tr>
<% } %>
</tbody>
</table>
<br>
<table align=center border=0 cellpadding=0 cellspacing=2 width="95%">
<tbody>
<tr valign=center>
<td align=middle> <br>
<table border=0 cellpadding=0 cellspacing=0>
<tr>
<td>
<% if (stroperation=="addnew"){
%>
<input class=stbtm name=update onclick="javascript:if (checkform2()==false);" type=button value="更新记录">
<% }else{
if(stroperation=="modi"){
%>
<input class=stbtm name=update onclick="javascript:if (checkform()==false);" type=button value="更新记录">
<%
}else{
%>
<input class=stbtm type="button" name="button" value="新 增" onclick="javascript:window.location.href=<%=request.getrequesturi()%>?act=addnew;"><%
}
} %>
</td>
<td>
<input class=stbtm type="button" name="button" value="返 回" onclick="javascript:window.location.href=index.jsp;">
</td>
</tr>
</table>
</td>
</tr>
</table>
<p> </p>
</div>
</body>
</html>
<script language=javascript>
<!--
function checkform2()
{
var checkblank = /^(\s*|(\ )|(\.))*$/;

if (checkblank.test(dataform2.name.value))
{
alert("餐馆名称不能为空!");
dataform2.name.focus();
return false;
}

if (checkblank.test(dataform2.phone.value))
{
alert("餐馆电话不能为空!");
dataform2.phone.focus();
return false;
}
window.dataform2.submit();
}

function checkform()
{
var checkblank = /^(\s*|(\ )|(\.))*$/;
if (checkblank.test(dataform.name.value))
{
alert("餐馆名称不能为空!");
dataform.name.focus();
return false;
}

if (checkblank.test(dataform.phone.value))
{
alert("餐馆电话不能为空!");
dataform.phone.focus();
return false;
}


window.dataform.submit();
}
-->
</script>
说明:本文件的书写有很多地方并不简练,因为在程式的开发过程中,过分简练的程序往往会带来后期维护的困难。

开发心得:

doc.getelementsbytagname("restaurants").item(int i)的返回值是node 型,如果不是要调用它的属性值,没有必要强制转型为 element型。可以直接操作。本系统因为开发的参考资料的错误,所以全都采用了强制转型。可以在以后的开发中考虑使用node 直接进行操作。

trim() 和 interger.parseint() 函数都不可以接受null 型的数值

在tomcat 下左右的文件都是目录从tomcat 算起,具体情况请参见\webapps\canyin\jsp\userjudge.jsp 里关于xml 路径的写法。




文章整理:站长天空 网址:http://www.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

文章页数:[1] 


放大字体显示 缩小字体显示 打印文章 推荐给朋友
热门文章
·使用ASP实现文件上载(上传)的各种方法-ASP教程,ASP应用
·windows media player同步歌词秀全攻略
·无法加载DLL(OCI.DLL),如何解决?-ASP教程,ASP应用
·七款常用视频播放软件的截图功能介绍
·C#向Sql Server中插入记录时单引号的处理-.NET教程,C#语言
·rm、rmvb视频文件减肥指南
·流媒体播放器暴风影音使用技巧十则
·ASP生成静态htm页面基本代码!-ASP教程,ASP基础
·photoshop制作撕纸效果-网页设计,Photoshop
·用ashx动态生成文件-.NET教程,Asp.Net开发
最新文章
·用photoshop去除照片中文字_photoshop教程
·认识mpeg视频压缩标准及相关编码格式_媒体工具教程
·flvix flv流媒体视频转换下载一步完成_媒体工具教程
·后sp时代 搜索联盟广告是站长们战略主攻方向_网赚技巧
·网络赚钱:利用好你的博客_网赚技巧
·百度主题推广申请要求大大降低_网赚技巧
·黔江小伙龚节毅:一人办全国顶级音乐网_站长访谈
·徐志勇 网站做得好不好网民说了算_站长访谈
·杨云:以模拟的炒股软件模拟炒股_站长访谈
·三招两式 提高博客的访问量_站长心得
相关主题
  • 使用jsp完成文件可定制上载-JSP教程,Jsp/Servlet
  • 使用JSP + JAVABEAN + XML 开发的一个例子-JSP教程,Jsp/Servlet
  • 使用jsp实现word、excel格式报表打印-JSP教程,Jsp/Servlet
  • 使用JSP对文件下载的控制-JSP教程,Jsp/Servlet
  • 使用JSP读取客户端信息-JSP教程,Jsp/Servlet
  • 西部数码虚拟主机

    友情链接
    CNNIC 西部数码
    万网 自助建站
    虚拟主机 asp空间
    域名注册 域名
    域名申请 主页空间
    论坛空间 网站空间
    国际域名 虚拟空间
    空间租用 DDOS防火墙
    成都主机托管 四川主机托管
    主机租用 服务器租用
    网站目录 自助建站
    虚拟主机 网址大全
    软件下载
    自助链接
    虚拟主机资讯 特价虚拟主机
    版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
    关于我们:站长天空:专业提供最新的站长资讯、在线教程、虚拟主机权威评测、虚拟主机性能对比、网站制作教程,开发教程,站长工具。包括网页制作教程、冲浪宝典、编程参考、操作系统、软件教学、行业动态等。
    特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
    发表评论 打印  刷新     关闭