留言板的一点小问题,求大神指点一下,谢谢
各位好,我想做一个像微博那样的界面,上面是两个输入框(一个输入用户名,一个输入内容),然后下面就显示用户名+内容,我现在是不知道怎么输入内容后,然后调用增添进数据库这个jsp文件,求大神帮帮忙???、下面是我的代码,
输入框:
ia.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<html>
<body>
<form method="post">
<div style="margin: 0 auto; width: 100%; position: absolute;text-align: center;">
发帖人ID: <input type="text" name="name" style="height:30px;width:300px"><BR><br>
<textarea name="con" rows="4" cols="20" style="height:100px;width:370px"></textarea><BR>
<BR>
<div style="position:absolute; top:160; right:380; width:200px;">
<input type="submit" value="发布"> <div><div>
</form>
<jsp:include page="sc.jsp" flush="true"></jsp:include>
</body>
</html>
添加进数据库的:
ib.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
<html>
<body>
<%
request.setCharacterEncoding("UTF-8");
String name = request.getParameter("name");
String con = request.getParameter("con");
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/S2010170135?useUnicode=true&characterEncoding=utf-8","S2010170135","19");
Statement stat = conn.createStatement();
String sql = "INSERT INTO T_STUDENT(STUNO,STUNAME) VALUES('" +name+"','"+con + "')";
int i=stat.executeUpdate(sql);
stat.close();
conn.close();
%>
</body>
</html>
查询数据库的,就是用来显示内容的
sc.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
<html>
<body>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/S2010170135?useUnicode=true&characterEncoding=utf-8","S2010170135","19");
Statement stat = conn.createStatement();
String sql = "SELECT STUNAME FROM T_STUDENT WHERE STUNO='的'";
ResultSet rs = stat.executeQuery(sql);
while(rs.next()){
String STUNAME= rs.getString("STUNAME");
out.println(STUNAME);
}
stat.close();
conn.close();
%>
</body>
</html>