标题:留言板的一点小问题,求大神指点一下,谢谢
只看楼主
zhoyuansheng
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-10-25
结帖率:0
已结贴  问题点数:20 回复次数:1 
留言板的一点小问题,求大神指点一下,谢谢
各位好,我想做一个像微博那样的界面,上面是两个输入框(一个输入用户名,一个输入内容),然后下面就显示用户名+内容,我现在是不知道怎么输入内容后,然后调用增添进数据库这个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>
搜索更多相关主题的帖子: position absolute 用户名 
2012-10-25 22:27
hhwz
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:87
帖 子:687
专家分:4502
注 册:2011-5-22
得分:20 
提交到添加的JSP就行了
2012-10-31 11:12



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-384438-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.167875 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved