Java Web--增删改查之一界面jsp的操作部分
Java Web--增删改查之一界面jsp的操作部分
拯救世界的小安安 发表于4年前
Java Web--增删改查之一界面jsp的操作部分
  • 发表于 4年前
  • 阅读 2139
  • 收藏 1
  • 点赞 1
  • 评论 0

腾讯云 技术升级10大核心产品年终让利>>>   

摘要: 一个example。基本的增删改。

增的jsp:

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@page import="java.util.*" %>
<%@page import="entity.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="javascript">
function check(){
  var inputs = document.getElementsByTagName('input');
  for(var i=0,len=2;i<len;i++){
    if(inputs[i].value.replace(/\s/g,'') == ''){
     alert('必填项不能为空!');
     inputs[i].focus();
     return false;
    }
  }
  return true;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<div align="center">
<H3>发布楼盘信息</H3>
<form id="form1" name="form1" method="post" action="BuildingServlet?action=add">
 <table width="90%" border="1" class="tableEdit">
      <tr>
        <td width="34%">楼盘信息ID</td>
        <td width="66%">
          <label>
            <input type="text" name="Id" id="Id" />
          </label>
        *</td>
      </tr>
      <tr>
        <td>公司</td>
        <td><input type="text" name="Company" id="Company" />
          *</td>
      </tr>
      <tr>
        <td>联系电话</td>
        <td><input type="text" name="Phone" id="Phone" /> </td>
      </tr>
      <tr>
        <td>描述</td>
        <td><input type="text" name=" Description" id="Description" />
          </td>
      </tr>
      <tr>
        <td colspan="2"><label>
          <input type="submit" name="button" id="button" value="提交" />
        </label></td>
        </tr>
    </table>
   </form>
   </div>
</body>
</html>

查的jsp:

<%@ page language="java" contentType="text/html; charset=utf-8"	pageEncoding="utf-8"%>
<%@page import="java.util.*"%>
<%@page import="entity.*"  %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>查询楼盘信息</title>
</head>
<body>

	<table width="834" border="0" cellpadding="0" cellspacing="0">
		<tr>			
			<td height="30" bgcolor="#029AC5" class="txt" align="center">查询楼盘信息</td>
		</tr>
	</table>	
	<%
	Building building=(Building)request.getAttribute("building");
	if(building!=null){	  
	%>
	楼盘ID:<%=building.getId() %><br />
	 公司:<%=building.getCompany() %><br />
	电话:<%=building.getPhone() %><br /> 
	描述:<%=building.getDescription() %><br />
	状态:<%=building.getStatus() %><br />
	<%
	}
	else
	{  
	%>
	<jsp:useBean id="service" class="service.BuildingService" scope="session"/>
	<%
		List<Building> projectlist=service.fill();
		Iterator<Building> iterproject=projectlist.iterator();
	%>
	<table width="800" border="0" align="center" cellpadding="0"
		cellspacing="0">
		
		<tr>
			<td height="30" colspan="3"><table width="100%" border="1"
					align="center" cellpadding="0" cellspacing="0">
					<tr>
						<td width="30%" height="20" align="center" bgcolor="#80C6FF"><span
							class="txt"><span class="titletxt">楼盘ID</span></span></td>
						<td width="35%" height="20" align="center" bgcolor="#80C6FF"
							class="titletxt"> 公司</td>
						<td width="35%" height="20" align="center" bgcolor="#80C6FF"
							class="titletxt">相关操作</td>
					</tr>
					<%
						while(iterproject.hasNext()){   
							Building Building1=iterproject.next();
					%>
					<tr>
						<td width="30%" height="20" align="center" bgcolor="#FFF5D7"><span
							class="txt"><%=Building1.getId()%></span></td>
						<td width="35%" height="20" align="center" bgcolor="#FFF5D7"><span
							class="txt"><%=Building1.getCompany()%></span></td>
						<td width="35%" height="20" align="center" bgcolor="#FFF5D7"><span
							class="txt">
							<a href="BuildingServlet?id=<%=Building1.getId()%>&action=list2">【详细】</a></span></td>
					</tr>
					<%
						}
					 }
					%>
				</table></td>
		</tr>
	</table>
</body>
</html>

删的jsp:

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@page import="java.util.*" %>
<%@page import="entity.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>

	<table width="834" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td height="30" background="images/title01.jpg" class="title">&gt;&gt;楼盘信息列表</td>
			
			<td width="27" height="30"><img src="images/title02.jpg"
				width="27" height="30" /></td>
			
		</tr>
	</table>	

	<table width="800" border="0" align="center" cellpadding="0"
		cellspacing="0">
		<tr>
			<td height="30" colspan="3" bgcolor="#029AC5" class="titletxt">&#8226;楼盘信息</td>
		</tr>
		<tr>
			<td height="30" colspan="3">
			<form action="BuildingServlet?action=delete2" method="post">	
			<table width="100%" border="1"
					align="center" cellpadding="0" cellspacing="0">
					<tr>
					    <td width="10%" align="center" bgcolor="#80C6FF" class="titletxt">选择</td>
						<td width="25%" height="30" align="center" bgcolor="#80C6FF"><span
							class="txt"><span class="titletxt">楼盘信息ID</span></span></td>
						<td width="30%" height="30" align="center" bgcolor="#80C6FF"
							class="titletxt">公司</td>
						<td width="35%" height="30" align="center" bgcolor="#80C6FF"
							class="titletxt">相关操作</td>
					</tr>
					<%
					    List<Building> buildingDelete=(List<Building>)request.getAttribute("buildingDelete");
						for(Building building:buildingDelete){
					%>
					<tr>
					    <td align="center"><input name="Id" width="15%"  bgcolor="#FFF5D7" type="checkbox" value="<%=building.getId()%>" /></td>
						<td width="25%" height="30" align="center" bgcolor="#FFF5D7"><span
							class="txt"><%=building.getId()%></span></td>
						<td width="30%" height="30" align="center" bgcolor="#FFF5D7"><span
							class="txt"><%=building.getCompany()%></span></td>
						<td width="35%" height="30" align="center" bgcolor="#FFF5D7"><span
							class="txt">
							<a href="BuildingServlet?action=delete3&id=<%=building.getId()%>">【删除】</a></span></td>
					</tr>
					<%	
					 }
					%>
				 <tr>
					<td width="10%" align="left" bgcolor="#80C6FF" class="titletxt" colspan="4">
					      <input type="submit" value=" 删除选择"/>     
					 </td>		
				</tr>
				</table>
				</form>	
			</td>
		</tr>
	</table>
</body>
</html>

改的jsp:界面效果就不上图了

<%@ page language="java" contentType="text/html; charset=utf-8"	pageEncoding="utf-8"%>
<%@page import="java.util.*"%>
<%@page import="entity.*"  %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>编辑楼盘信息</title>
</head>
<body>

	<table width="834" border="0" cellpadding="0" cellspacing="0">
		<tr>
			
			<td height="30" bgcolor="#029AC5" class="txt" align="center">编辑楼盘信息</td>
		</tr>
	</table>	

	<%
	Building building=(Building)request.getAttribute("building");
	if(building!=null){	  
	%>
<table width="100%" height="30" align="center" cellpadding="0" cellspacing="0" >
 <tr>
 <td height="30" align="center"><form id="form1" name="form1" method="post" action="BuildingServlet?action=update2">
 <table width="100%" border="1" align="center" cellpadding="0" cellspacing="0" bgcolor="E7E7E7">
 <tr>
 <td width="24%" height="30" align="right" class="txt"><span class="txt">楼盘ID</span></td>
 <td height="30" align="left" ><label for="textfield"></label>
 <input type="text" name="Id" id="Id" value=<%=building.getId()%> disabled/>
  <input type="hidden" name="Id" id="Id" value=<%=building.getId()%> /><span class="txt">*</span></td>
  </tr>
  

   <tr>
 <td width="24%" height="30" align="right" class="txt"><span class="txt"> 公司</span></td>
 <td height="30" align="left" >
 <input  height="20" width="400" type="text" name="Company" id="Company" value=<%=building.getCompany()%>/>  <span class="txtred">*</span></td>
  </tr>
     
   <tr>
 <td  height="30" align="right" class="txt">电话</td>
 <td height="30" align="left" >
 <input  height="20" width="150" type="text" name="Phone" id="Phone" value=<%=building.getPhone()%>/>  </td>
  </tr>
  <tr>
 <td  height="30" align="right" class="txt">描述:</td>
 <td height="30" align="left" >
 <input  height="20" width="200" type="text" name="Description" id="Description" value=<%=building.getDescription()%>/>  </td>
  </tr>

  <tr>
 <td  height="30" align="right" class="txt">状态:</td>
 <td height="30" align="left" ><span class="txtred">
 <input  height="20" width="200" type="text"  id="Status" value=<%=building.getStatus()%>/>  </span></td>
  </tr>
  </table>
  
<p>
 <input type="submit" name="button" id="button" value="确定"/>
</p>
</form>
<p>&nbsp;</p></td>
</tr>
</table>
<% }else{%>
	<jsp:useBean id="service" class="service.BuildingService" scope="session"/>
	<%
		List<Building> projectlist=service.fill();
		Iterator<Building> iterproject=projectlist.iterator();
	%>
	<table width="800" border="0" align="center" cellpadding="0"
		cellspacing="0">
		
		<tr>
			<td height="30" colspan="3"><table width="100%" border="1"
					align="center" cellpadding="0" cellspacing="0">
					<tr>
						<td width="30%" height="20" align="center" bgcolor="#80C6FF"><span
							class="txt"><span class="titletxt">楼盘ID</span></span></td>
						<td width="35%" height="20" align="center" bgcolor="#80C6FF"
							class="titletxt"> 公司</td>
						<td width="35%" height="20" align="center" bgcolor="#80C6FF"
							class="titletxt">相关操作</td>
					</tr>
					<%
						while(iterproject.hasNext()){   
							Building Building1=iterproject.next();
					%>
					<tr>
						<td width="30%" height="20" align="center" bgcolor="#FFF5D7"><span
							class="txt"><%=Building1.getId()%></span></td>
						<td width="35%" height="20" align="center" bgcolor="#FFF5D7"><span
							class="txt"><%=Building1.getCompany()%></span></td>
						<td width="35%" height="20" align="center" bgcolor="#FFF5D7"><span
							class="txt">
							<a href="BuildingServlet?id=<%=Building1.getId()%>&action=update">【修改】</a></span></td>
					</tr>
					<%
						}
					 }
					%>
				</table></td>
		</tr>
	</table>
</body>
</html>

接下来是数据库的sql:

use master
go
create database EstateDB
go
use EstateDB
go
create table T_building(
	Id  varchar(20) primary key  not null,
    Company varchar(40)   not null,
    Phone varchar(20)  not null,
    Description varchar(200) not null,
    Status varchar(8)
)
insert into  T_building(Id,Company,Phone,Description,Status) 
values ('001','恒大地产','0731-88859908','东湖花园,10.1开盘','审核通过')
 insert into T_building(Id,Company,Phone,Description,Status)
 values('002','旭日地产','0731-82285588','戏子花园,10.1开盘','未审核')
 insert into T_building(Id,Company,Phone,Description,Status)
 values('003','万达地产','0731-84155688','万哒花园,10.1开盘','未审核')
 go

调试下,就可以运行啦。

还有主页面的code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>楼盘信息发布</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />

</head>
<body >
<div >
<table width="900" height="20" border="0" align="center">
  <tr>
    <td colspan="2"><img src="images/xian2.jpg" width="900"  /></td>
  </tr>
  <tr>
    <td width="170" valign="top" bgcolor="#FFFFCC" align="center"><ul>
      <li><a href="BuildingServlet?action=add" target="content">发布楼盘信息</a></li>
      <li><a href="BuildingServlet?action=list" target="content">查询楼盘信息</a></li>
      <li><a href="buildingUpdate.jsp" target="content">编辑楼盘信息</a></li>
      <li><a href="BuildingServlet?action=delete" target="content">删除信息发布</a></li>
    </ul>
    </td>
    <td width="730" valign="top">
     <iframe frameborder="0" name="content" width="100%" height="590" scrolling="auto">
     <marquee>欢迎管理员的进入</marquee>
     </iframe>
    </td>
  </tr>
</table>
 
  </div>
</body>
</html>

会在操作二中附源码和后台java code。

标签: jsp 增删改查
共有 人打赏支持
粉丝 3
博文 27
码字总数 26827
×
拯救世界的小安安
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: