以前初学时收集的一些代码(JSP)
来源:互联网 发布:末日人工智能怎么算赢 编辑:程序博客网 时间:2024/05/01 03:10
下面的程序是test.jsp文件:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!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=gb2312">
<title>测试页</title>
<script LANGUAGE="javascript">
<!--
function test_onsubmit() {
if (document.test.name.value=="")
{
alert("Sorry,姓名没有输入!")
document.test.name.focus()
return false
}
else if(document.test.password.value=="" || document.test.password.value.toUpperCase()=="HTTP://")
{
alert("Sorry,密码没有输入!")
document.test.password.focus()
return false
}
}
//-->
</script>
<link rel="stylesheet" href="css/style.css"> _fcksavedurl=""css/style.css">"
</head>
<body>
<div align="center">
<p> </p>
<p>测试页</p>
<form name="test" method="post" LANGUAGE="javascript" onsubmit="return test_onsubmit()" action="doadd.jsp">
<p>姓名:
<input name="name" type="text" size="16" maxlength="16">
</p>
<p>密码:
<input name="password" type="text" size="16" maxlength="16">
</p>
<p>
<input type="submit" name="Submit" value="提交">
</p>
</form>
<p> </p>
</div>
</body>
</html>
下面是doadd.jsp文件:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%! String name,password;%>
<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test";
//test为数据库
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
request.setCharacterEncoding("GB2312");
name=request.getParameter("name")[0].trim();
password=request.getParameter("password")[0].trim();
stmt.executeUpdate("insert into test1(name,password) values("+name+","+password+")");
%>
<%
stmt.close();
conn.close();
%>
我在 servlet 中 用 response 重新定向客户端
父窗体为:aa.jsp
servlet 中定向代码为: response.rendRedirect("bb.jsp");
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn=DriverManager.getConnection"jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=MYDATA","sa","123");
3.
<%Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:@myoracle";
String uid="system";
String pwd=" manager ";
Connection con = DriverManager.getConnection(url,uid,pwd);
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from book");
while(rst.next())
{
out.println("<tr>");
out.println("<td>"+rst.getString("BOOKID")+"</td>");
out.println("<td>"+rst.getString("bookname")+"</td>");
out.println("<td>"+rst.getString("publisher")+"</td>");
out.println("<td>"+rst.getFloat("price")+"</td>");
out.println("</tr>");
}
rst.close();
stmt.close();
con.close();
%>
</table>
</body>
</html>
<%@page contentType="text/html;charset=gb2312" language="java" import="java.sql.*" errorPage=""%>
<html>
<head>
<title>
读数据库
</title>
</head>
<body>
<%
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException e){
%>
<%=e%>
<%
}
try{
Connection con=DriverManager.getConnection("jdbc:odbc:test2");
Statement sql=con.createStatement();
ResultSet rs=sql.executeQuery("select * from table1");
while(rs.next())
{
%>
<%=rs.getString("name")%>
<%=rs.getString("password")%>
<%
}
rs.close();
sql.close();
con.close();
}catch(SQLException ee){
%>
<%=ee%>
<%
}
%>
nihao!
</body>
</html>
- 以前初学时收集的一些代码(JSP)
- 以前收集的一些安全文章
- 以前收藏的一些代码
- JSP初学的一些记录
- 收集的一些代码
- 一些代码的收集
- 收集:初学ASP.Net时在论坛收藏收集的一些资料备忘
- 以前收集的
- 初学jsp的一些问题的总结
- 一些好的代码,收集
- 收集的一些js代码
- C# XML 操作(以前写的加现在收集的,备以后忘了,还找以前的代码库)
- jsp的一些小技巧, 收集....
- 初学ASP.Net时在论坛收藏收集的一些资料备忘
- 初学ASP.Net时在论坛收藏收集的一些资料备忘
- 初学ASP.Net时在论坛收藏收集的一些资料备忘
- 初学ASP.Net时在论坛收藏收集的一些资料备忘
- 初学ASP.Net时在论坛收藏收集的一些资料备忘
- 连接到数据库(JSP)
- 禁用“命令提示符”
- SWT里的表格编程(翻译)
- 使用Eclipse完成经典的重构
- 2000 Server 系统安全完全配置方案
- 以前初学时收集的一些代码(JSP)
- 各种数据库连接代码(JSP)
- My first blog
- 纪念爱因斯坦
- 黑客与骇客
- WinXP运行命令大集合
- 木马藏匿地详解
- 多媒体定时器(回调函数定时方式)控制类
- 向各位大侠请教