add_message.jsp~7~
资源名称:JSP02.rar [点击查看]
上传用户:top0756
上传日期:2022-08-11
资源大小:6501k
文件大小:1k
源码类别:
Jsp/Servlet
开发平台:
VBScript
- <%@ page import="java.sql.*" %>
- <HTML>
- <HEAD>
- <TITLE>add message into table </TITLE>
- </HEAD>
- <BODY>
- <%
- String name=request.getParameter("name");
- String mail=request.getParameter("mail");
- String title=request.getParameter("title");
- String content=request.getParameter("content");
- if(name==null)
- name="";
- if(title==null)
- title="";
- if(content==null)
- content="";
- if(mail==null)
- mail="";
- if(name.length()==0)
- out.println("留言人姓名不能为空!");
- else if(title.length()==0)
- out.println("留言主题不能为空!");
- else if(content.length()==0)
- out.println("留言内容不能为空!");
- else
- {
- java.util.Date date=new java.util.Date();
- String datetime=new Timestamp(date.getTime()).toString();
- try
- {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- String userName = "sa";
- String password = "";
- String URL="";
- String sql="";
- String url="jdbc:odbc:dsn112";
- Connection con=DriverManager.getConnection(url,userName,password);
- PreparedStatement stm=con.prepareStatement("insert into message values(?,?,?,?,?)");
- stm.setString(1,title);
- stm.setString(2,name);
- if(mail.length()==0)
- stm.setString(3,null);
- else stm.setString(3,mail);
- stm.setString(4,datetime);
- stm.setString(5,content);
- try
- {
- stm.executeQuery();
- } catch(Exception e)
- {}
- con.close();
- }
- catch (Exception e)
- {}
- %>
- <jsp:forward page="view_message.jsp" />
- <%
- }
- %>
- </body>
- </html>