侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

JSP简单添加,查询功能代码

Java  /  管理员 发布于 7年前   241

本文实例讲述了JSP简单添加,查询功能。分享给大家供大家参考。具体如下:

JSP技术:

public class ISOtoGb2312{public static String convert( String str ){try{byte<> bytesStr=str.getBytes( "ISO-8859-1" ) ;return new String( bytesStr, "gb2312" ) ; }catch( Exception ex){return str ;}}}

<%@ page contentType="text/html; charset=GB2312" %><html><head><title>输入数据</title></head><body bgcolor="#ffffff"><h1>请输入数据:</h1><hr><form method="POST" action="insert.jsp"><!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.txt"S-Format="TEXT/CSV" S-Label-Fields="TRUE" --><p> </p><p> </p><p><img border="0" src="https:/article/img/cisco.gif" width="70" height="81"><font size="5" color="#0000FF"><b>学 号:</b></font><input type="text" name="id" size="25"> <img border="0" src="https:/article/img/cisco.gif" width="70" height="81"><font size="5" color="#0000FF"><b>性 别</b></font><font size="5" color="#0000FF"><b>:</b></font><input type="text" name="sex" size="24"></p><p><img border="0" src="https:/article/img/cisco.gif" width="70" height="81"><font size="5" color="#000080"><b>姓 名:</b></font><input type="text" name="name" size="25"> <img border="0" src="https:/article/img/cisco.gif" width="70" height="81"><font size="5" color="#0000FF"><b>年 龄: </b></font><input type="text" name="age" size="24"></p><p><img border="0" src="https:/article/img/cisco.gif" width="70" height="81"><font size="5" color="#000080"><b>地 址:</b></font><input type="text" name="addr" size="84"> </p><p> </p><p><input type="submit" value="提交" name="B1" style="font-size: 14pt; font-weight: bold"><input type="reset" value="全部重写" name="B2" style="font-size: 14pt; font-weight: bold"></p></form></body></html>

<%@ page contentType="text/html; charset=GB2312" %><%@ page import = "java.sql.*"%><%@ page language = "java"%><%@ page import = "test.ISOtoGb2312"%><html><head><title>添加数据</title></head><body bgcolor="#ffffff"><h1>接收数据,添加到数据库.</h1><%Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //载入驱动程序类别Connection con = DriverManager.getConnection("jdbc:odbc:zjyds1"); //建立数据库链接Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);String strSQL;strSQL = "INSERT INTO tab02(id, name, sex, " +"age, addr) Values (" +ISOtoGb2312.convert( request.getParameter("id")) + "," +ISOtoGb2312.convert( request.getParameter("name")) + "," +ISOtoGb2312.convert( request.getParameter("sex")) + "," +ISOtoGb2312.convert( request.getParameter("age")) + "," +ISOtoGb2312.convert( request.getParameter("addr")) + ")";stmt.executeUpdate(strSQL);ResultSet rs; //建立ResultSet(结果集)对象rs = stmt.executeQuery("SELECT * FROM tab02"); //执行SQL语句%><CENTER><TABLE bgcolor=pink><TR bgcolor=silver><TD><B>编号</B></TD><TD><B>姓 名 </B></TD><TD><B>性 别</B></TD><TD><B> 年 龄</B></TD><TD><B>地 址</B></TD></TR><%//利用while循环将数据表中的记录列出while (rs.next()){%><TR bgcolor=white><TD><B><%= rs.getString("id") %></B></TD><TD><B><%= rs.getString("name") %></B></TD><TD><B><%= rs.getString("sex") %></B></TD><TD><B><%= rs.getString("age") %></B></TD><TD><B><%= rs.getString("addr") %></B></TD></TR><%}rs.close(); //关闭ResultSet对象stmt.close(); //关闭Statement对象con.close(); //关闭Connection对象%></TABLE></CENTER><h3><a href="https:/article/jsp1.jsp">返回</a></h3></body></html>

jsp1:

<%@ page contentType="text/html; charset=GB2312" %><%@ page import="com.borland.internetbeans.*,com.borland.dx.dataset.*,com.borland.dx.sql.dataset.*" %><%@ taglib uri="/internetbeans.tld" prefix="ix" %><%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %><html><head><title>jsp1</title></head><jsp:useBean id="jsp1BeanId" scope="session" class="test.Jsp1Bean" /><jsp:setProperty name="jsp1BeanId" property="*" /><body bgcolor="#ff00ff"><h1>JBuilder Generated JSP<br><hr>这是第一次使用JSP技术 !!!----2004/3/1--南昌大学软件学院----</h1><h3><a href="https:/article/tmp/page_1.htm">另一页</a></h3><br><h3><a href="https:/article/jsp2.jsp">下一页</a></h3><br><h3><a href="https:/article/DBBean.jsp">数据库</a></h3><form method="post"><br>Enter new value : <input name="sample"><br><br><input type="submit" name="Submit" value="Submit"><input type="reset" value="Reset"><br>Value of Bean property is :<jsp:getProperty name="jsp1BeanId" property="sample" /></form><h3><a href="https:/article/jsp4.jsp">登录</a></h3></body></html>

Jsp1Bean.java

package test;/*aaaaaaabbbbbbbccccccccc*//*** <p>Title: </p>* <p>Description: </p>* <p>Copyright: Copyright (c) 2004</p>* <p>Company: </p>* @author not attributable* @version 1.0*/public class Jsp1Bean {private String sample = "Start value";//Access sample propertypublic String getSample() {return sample;}//Access sample propertypublic void setSample(String newValue) {if (newValue!=null) {sample = newValue;}}}

jsp2:

<%@ page contentType="text/html; charset=GB2312" %><%@ page import="java.sql.*" %><%@ page language="java" %><HTML><HEAD><TITLE>顺序取得数据</TITLE></HEAD><BODY><CENTER><FONT SIZE = 5 COLOR = blue>顺序取得数据</FONT></CENTER><BR><HR><BR><CENTER><%Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //载入驱动程序类别Connection con = DriverManager.getConnection("jdbc:odbc:zjyds1"); //建立数据库链接Statement stmt = con.createStatement(); //建立Statement对象ResultSet rs; //建立ResultSet(结果集)对象rs = stmt.executeQuery("SELECT * FROM tab01"); //执行SQL语句%><TABLE bgcolor=pink><TR bgcolor=silver><TD><B>学 号</B></TD><TD><B>姓 名 </B></TD><TD><B>性 别 </B></TD><TD><B>年 龄 </B></TD><TD><B>地 址</B></TD></TR><%//利用while循环将数据表中的记录列出while (rs.next()){%><TR bgcolor=white><TD><B><%= rs.getString("id") %></B></TD><TD><B><%= rs.getString("name") %></B></TD><TD><B><%= rs.getString("sex") %></B></TD><TD><B><%= rs.getString("age") %></B></TD><TD><B><%= rs.getString("addr") %></B></TD></TR><%}rs.close(); //关闭ResultSet对象stmt.close(); //关闭Statement对象con.close(); //关闭Connection对象%></TABLE></CENTER></BODY></HTML>

jsp3:

<%@ page contentType="text/html; charset=GB2312" %><html><head><title>jsp3</title></head><jsp:useBean id="jsp3BeanId" scope="session" class="test.Jsp3Bean" /><jsp:setProperty name="jsp3BeanId" property="*" /><body bgcolor="#ffffc0"><h1>JBuilder Generated JSP</h1><form method="post"><br>Enter new value : <input name="sample"><br><br><br><input type="submit" name="Submit" value="Submit"><input type="reset" value="Reset"><br>Value of Bean property is :<jsp:getProperty name="jsp3BeanId" property="sample" /></form></body></html>

jsp4:

<%@ page contentType="text/html; charset=GB2312" %><html><head><title>登录</title></head><body bgcolor="#ffffc0"><form method="POST" action="jsp6.jsp"><p align="center">用户名:<input type="text" name="username" size="20"></p><p align="center">密 码:<input type="password" name="password" size="20"></p><p align="center"><input type="radio" value="manage" checked name="select">管理  <input type="radio" name="select" value="statistic">统计</p><p align="center"><input type="submit" value="登 录" name="login"><input type="reset" value="重 写" name="reset"></p></form></body></html>

jsp6:

<%@ page contentType="text/html; charset=GB2312" %><html><head><title>接收数据</title></head><body bgcolor="#ffffff"><%String user,pwd,choice;user=request.getParameter("username");pwd=request.getParameter("password");choice=request.getParameter("select");if(choice.equals("manage")){//user select manage.%><jsp:forward page="jsp7.jsp"><jsp:param name="username" value="<%=user%>"/><jsp:param name="password" value="<%=pwd%>"/></jsp:forward><%}else{//user select statistic%><jsp:forward page="jsp8.jsp"><jsp:param name="username" value="<%=user%>"/><jsp:param name="password" value="<%=pwd%>"/></jsp:forward><%}%></body></html>

jsp7:

<%@ page contentType="text/html; charset=GB2312" %><html><head><title>jsp7</title></head><body bgcolor="#ffffff"><h1>这是管理页 !!!</h1><br><%String user,pwd;user=request.getParameter("username");pwd=request.getParameter("password");%>username is: <%=user%><br>password is: <%=pwd%><br></body></html>

jsp8:

<%@ page contentType="text/html; charset=GB2312" %><html><head><title>jsp8</title></head><body bgcolor="#ffffff"><h1>这是统计页 !!!</h1><br><%String user,pwd;//user=request.getParameter("username");user=new String(request.getParameter("username").getBytes("ISO8859_1"));pwd=request.getParameter("password");%>username is: <%=user%><br>password is: <%=pwd%><br></body></html>

input.html

<HTML><HEAD><TITLE>网页引导</TITLE></HEAD><BODY><CENTER><FONT SIZE = 5 COLOR = blue>网页引导</FONT></CENTER><BR><HR><BR><FORM action="sendRedirect.jsp" method=post name=form1><P>姓名 : <INPUT name=inputName ></P><P>E-Mail : <INPUT name=inputE_Mail ></P><INPUT name=submit type=submit value=送出></FORM></BODY></HTML

sendRedirect.jsp:

<%@ page contentType="text/html; charset=GB2312" %><%@ page language="java" %><%String Name = request.getParameter("inputName");String E_Mail = request.getParameter("inputE_Mail");if(Name.equals("") || E_Mail.equals(""))//检查Name或E_Mail是否完成资料输入response.sendRedirect("sendRedirect.html"); //若未完成资料输入则将网页导向sendRedirect.html%><HTML><HEAD><TITLE>网页引导</TITLE></HEAD><BODY><CENTER><FONT SIZE = 5 COLOR = blue>网页引导</FONT></CENTER><BR><HR><BR><P>您的大名是:<%= Name %></P><P>E-Mail帐号为:<%= E_Mail %></P><p><a href="https:/article/../jsp1.jsp">返回</a></p></BODY></HTML>

sendRedirect.html:

<HTML><HEAD><TITLE>网页引导</TITLE></HEAD><BODY><CENTER><FONT SIZE = 5 COLOR = blue>网页引导</FONT></CENTER><BR><HR><BR><FORM action="sendRedirect.jsp" method=post name=form1><font size=5 color=red>你输入的信息不完整,请重新输入!</font><br><P>姓名 : <INPUT name=inputName ></P><P>E-Mail : <INPUT name=inputE_Mail ></P><INPUT name=submit type=submit value=送出></FORM></BODY></HTML>

希望本文所述对大家的JSP程序设计有所帮助。


  • 上一条:
    JSP结合js实现img中src更新请求的方法
    下一条:
    jsp中page指令用法详解
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 在java中实现的脱敏工具类代码示例分享(0个评论)
    • zookeeper安装流程步骤(0个评论)
    • 在java中你背的“八股文”可能已经过时了(2个评论)
    • 在php8.0+版本中使用属性来增加值代码示例(3个评论)
    • java 正则表达式基础,实例学习资料收集大全 原创(0个评论)
    • 近期文章
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-11
    • 2018-03
    • 2020-03
    • 2023-05
    • 2023-11
    • 2024-01
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客