⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dealaddboard.jsp

📁 机械工业出版社的《jsp2.0动态网站开发实例指南》的源代码
💻 JSP
字号:
<!--dealaddboard.jsp-->
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%!
	public String codeString(String s){
		String str=s;
                try{
			byte b[]=str.getBytes("ISO-8859-1");
			str=new String (b);
			return str;
		}catch(Exception e){return str;}
	}
%>
<%
	String fromid=request.getParameter("fromid");
	String title=request.getParameter("title");
	String message=request.getParameter("message");
	if(fromid==null)fromid="";
	if(title==null)title="";
	if(message==null)message="";
	if(fromid.equals("")||(title.equals("")&&message.equals(""))){
		out.print("<center><h1>请正确填写留言内容!</h1></center>");
	}
	else{
		java.util.Date date = new java.util.Date();
		String time=date.toString();
		title=codeString(title);
		message=codeString(message);
  		fromid=codeString(fromid); 
		try{
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			Connection con=DriverManager.getConnection("jdbc:odbc:board","","");
			Statement sql = con.createStatement();
			String insert="insert into board values (?,?,?,?)";
			PreparedStatement pstmt=con.prepareStatement(insert);
			pstmt.setString(1,time);
			pstmt.setString(2,message);
			pstmt.setString(3,fromid);
			pstmt.setString(4,title);
			pstmt.executeUpdate();
			pstmt.close();
			con.close();
			response.sendRedirect("board.jsp");
		}catch(SQLException e){
			out.print("SQL error!"+e);

		}catch(ClassNotFoundException e){
			out.print("CNF error!"+e);
		}
	}
%>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -