猿问

各位帮我看看为什么我提交的留言可以存到数据库,<div id="content 2"></div>却得不到一个返回至

第一个页面

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

    <%@ page  import="java.sql.*"%>

<%

String message1=(String)session.getAttribute("username");

if(message1!=null){

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


<html>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<head>

<style type="text/css">

div#container{width:1350px;height:1000px;margin-top: -3%;background-position: 0% 0%;margin-left: -7px;}

div#header {width:1350px; height:240px; margin-left: 0px;background-attachment:scroll;}

div#content1{ height:50px; width:1360px; float:left;margin-top: 0%;margin-left: 0%;}

div#content2{background:url("img/aa.jpg"); height:600px; width:350px; float:left;margin-top: 3%;margin-left: 3%;border-radius:25px;box-shadow: 10px 10px 5px #888888;}

div#content3{background:url("img/sw.jpg"); height:600px; width:730px; float:left;margin-top: 3%;margin-left: 10%;border-radius:25px;box-shadow: 10px 10px 5px #888888;}

div#content4 {background-color:#00FFFF;width:150px;height:150px;overflow: scroll}

h1{font-family: "华文行楷";font-size: 60px;color:black;font-style: italic;font-weight: bolder;letter-spacing: 15px;margin-left: 0px;}

h2{font-family: "隶书";font-size: 30px;color:black;font-style: italic;font-weight: bolder;letter-spacing: 15px;margin-left: 50px;}

.inputW{ width:660px; height:400px; margin-left: 110px;}

.inputf{ width:100px; height:30px; margin-left: 680px;}

body{background:url("img/rp.jpg");}

img{border-radius:100%;}

ul{float:left;width:100%;height:50px;padding:0;margin:0;list-style-type:none;}

a{float:left;width:319px;height:50px;text-decoration:none;text-align: center;color:black;background-color:green;padding:0.2em 0.6em;border-right:1px solid white;}

a:hover {background-color:white}

li {display:inline;}

div#footer{background:green;height:40px; width:1350px; float:left;margin-top:40px;margin-left: 0px;margin-bottom: 0px;}

</style>

<script type="text/javascript">

function check(){

var r=form1.textfield.value;

if(r!=""){

document.getElementById("s1").disabled=false;

}else{

document.getElementById("s1").disabled=true;

}

}

function sendtext(){

var text1=form1.textfield.value;

if(text1!=""){

createRequest("./insert1.jsp?text1="+text1);

}else {

 

}

}

function createRequest(url){

http_request=new XMLHttpRequest();

http_request.onreadystatechange=function(){

if(http_request.readyState==4){

if(http_request.status==200){

alert(http_request.status);

var t=document.getElementById("content2").innerHTML;

t=http_request.responseText;

}else{

alert(http_request.status);

alert("error");

}

}

}

http_request.open("POST",url,true);

http_request.send(null);

}

</script>


</head>

<body>

<div id=container>

<div id=header>

</div>

<div id=content1>

<ul>

<li><a href="shahua.jsp">沙画主页</a></li>

<li><a href="denglu.html">沙画图集</a></li>

<li><a href="denglu.html">沙画历史</a></li>

<li><a href="liuyan.jsp">给我留言</a></li>

</ul>

</div>

<div id=content2>

<br>

<h1 style="font-size:30px;letter-spacing: 3px">留言列表:</h1>

</div>

<div id=content3>

<h1 >留言板:</h1>

<form name="form1" action="" method="post">


<p>

<textarea name="textfield" cols="70" rows="23" style="margin-left:60px;" onkeyup="check()"></textarea>

</p>

<p align="center">

<input type="submit" value="提交" style="width:100px;height:30px" id="s1" disabled="disabled" onclick="sendtext()">&nbsp;&nbsp;

<input type="reset" value="取消"style="width:100px;height:30px;" name="r1">

</p>

</form>

</div>

<div id=footer>

</div>

</div>


</body>

<%} else{

response.setHeader("refresh", "3;URL=Login.jsp");

}


%>

</html>

第二个页面

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8" import="java.util.Date"%>

       <%@ page  import="java.sql.*"%>

<!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">

<title>Insert title here</title>

</head>

<body>

<%

request.setCharacterEncoding("UTF-8");

String time=new Date().toLocaleString();

String message=(String)session.getAttribute("username");

request.setCharacterEncoding("UTF-8");

String textfield=new String(request.getParameter("text1"));

Class.forName("com.mysql.jdbc.Driver");

Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/login?useSSL=true", "root" ,"123456");

String tl="insert into liuyan (name,time,content) values ('"+message+"','"+time+"','"+textfield+"')";

Statement stmt=con.createStatement();

int rs=stmt.executeUpdate(tl);

if(rs==1){

out.println("<html>");

out.println("<head><title></title></head>");

out.println("<body>");

out.println("<table width='300' border='0' align='left' cellpadding='0' cellspacing='1'>");

out.println("<tr>");

out.println("<td width='300' align='center'></td>");

out.println("</tr>");


for(int i=1;i<7;i++){

if(i==1){out.print("");}

if(i==2){out.print("<tr><td width='300' align='left' >"+"用户:"+message+"</td><tr>");}

if(i==3)

{i=4;out.print("<tr><td width='300' align='left'>"+time+"</td></tr>");}

if(i==5){out.print("<tr><td width='300' align='left' height='50' >"+"留言:"+"<textarea  style='overflow:scroll'  >"+textfield+"</textarea>"+"</td><tr>");}

if(i==6){out.print("<tr><td width='300' height='20' align='left'>"+"<a  href='delete1.jsp?id=' style='width:50px;height:20px;background-color:#90ee90;padding:0;border-radius:15px;box-shadow: 1px 1px 1px #888888'>"+"删除"+"</a>"+"</td></tr>");}

out.println("</table>");

out.println("</h1>");

out.println("</body>");

out.println("</html>");

}

   }else{  out.println("<html>");

out.println("<head><title>留言</title></head>");

out.println("<body style='text-align:center'>");

out.println("<div style='margin:100px auto' >");

%>

<% 

out.println("</div>");

out.println("</body>");

out.println("</html>");

  }

   stmt.close();

  con.close();

%>

</body>

</html>


慕粉4296528
浏览 1554回答 0
0回答
随时随地看视频慕课网APP

相关分类

MySQL
我要回答