日期:2014-05-17  浏览次数:20786 次

刚学jsp,期待大神们的到来!!!
DengRuServer.java

Java code

package DengRuServer;
import java.io.*;
import java.sql.*;
import java.sql.Date;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DengRuServer extends HttpServlet {
    String user,neirong,yanzhengma;
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        Connection  conn=null;
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();

        user=request.getParameter("user");        //通过ID获取前台的昵称
        neirong=request.getParameter("neirong");      
        yanzhengma=request.getParameter("yanzhengma");
        System.out.println("用户名:"+user+"内容:"+neirong);
        HttpSession session=request.getSession();
        //String code1=(String)session.getAttribute("code");

        //if(yanzhengma.equals(code1))                //验证码正确执行
        
            SimpleDateFormat matter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            
            String date=matter.format(new Date(1000));
            System.out.println("读取时间"+date);
            String sql="insert into shiyichanglang values('"+neirong+"','"+date+"','"+user+"')";
            try {
                conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/sss","root","hin19920309");
                System.out.println("连接数据库成功");
                Statement  sta=conn.createStatement();
                int rs=sta.executeUpdate(sql);
                System.out.println("数据插入成功");
            } catch (SQLException e) {
                e.printStackTrace();
            }
            String returnValues="<div><input name=user type=text>";
            returnValues=returnValues+neirong;
            returnValues=returnValues+"</input></div>";
            out.write(returnValues);
            System.out.println("数据插入成功");
            /*}else{                             //验证码错误执行
            String returnValues="alert('验证码错误!')";
            response.getWriter().write(returnValues);
        }
            out.flush();
            out.close();*/    
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        this.doGet(request, response);
    }
}




shiyichanglang.jsp

VBScript code
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!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=utf-8" />

<link href="css\Style_135.css" rel="stylesheet" type="text/css" />

<title>完全训练--诗意长廊</title>

<style>

#gn{

width:100%;

height:30px;

float:right;

clear: both;

text-align:right;

padding-right:8px;

padding-top:5px;

background-color: #FFFFFF;

filter:alpha(opacity=35);

color:#000000;

}

#gn table { text-align:right;}

#gn td { color:#000000;}

#gn a{color:#000000;}