add.jsp
来自「JSP的一个DEMO程序」· JSP 代码 · 共 42 行
JSP
42 行
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.sql.*" %>
<%!
Connection conn;
java.sql.Statement stmt;
ResultSet Rs;
String strSQL="";
%>
<%!
// 处理中文的函数,不要求
public String chstr(String str){
try{
String temp_p=str;
if(temp_p==null){temp_p="";}
byte[] temp_t=temp_p.getBytes("ISO-8859-1");
String temp=new String(temp_t);
return temp;
}catch(Exception e){
return "null";
}
}
%>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:quiz","","");
stmt=conn.createStatement();
strSQL="insert into t_record values('"+chstr(request.getParameter("s_date"))+
"','"+ chstr(request.getParameter("s_topic"))+"','"+
chstr(request.getParameter("s_content"))+ "')";
Rs=stmt.executeQuery(strSQL);
} catch(Exception e){
out.println(e.getMessage());
}
%>
日记已经保存,<a href="javascript:self.close()">关闭</a>
<!--
要求掌握JSP页面的结构和写法。
要求接收表单的数据。
要求掌握连接ODBC数据库。
掌握执行SQL语句的方法。
-->
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?