zoukankan      html  css  js  c++  java
  • 留言板(连接数据库)

    简单实现留言功能

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        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">
    <title>留言板</title>
    </head>
    <body>
    <form action="session0625.jsp" method="post" id="form1" name="form1">
    <div align="center">
    <table width="50%" border="0">
    <tr >
    <td width="10%">您的联系邮箱:</td>
    <td width="40%"><input type="text" name="email"/></td>
    </tr>
    </table>
    <table width="50%" border="0" height="40%">
    <tr><td>留言内容:</td></tr>
    <tr><td><input type="text" style=" 50%;height: 100%" name="liuyan"/></td></tr>
    <tr><td><input type="submit" value="提交"/></td></tr>
    
    </table>
    
    </div>
    
    </form>
    
    
    </body>
    </html>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        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">
    <title>session</title>
    </head>
    <body>
    <%
    String email=new String(request.getParameter("email").getBytes("ISO-8859-1"),"UTF-8");
    session.setAttribute("email",email);
    String liuyan=new String(request.getParameter("liuyan").getBytes("ISO-8859-1"),"UTF-8");
    session.setAttribute("liuyan",liuyan);
    %>
    <form action="result0625.jsp" method="post">
    <table>
    <tr><td>确定添加留言?</td></tr>
    <tr>
    <td><input type="submit" value="确定"/></td>
    <td><input type="reset" value="取消"/></td>
    </tr>
    
    </table>
    
    
    </form>
    <%-- 
    您的邮箱地址是:
    <%=email %>
    <br>
    您的留言内容是:
    <%=liuyan %>
    --%>
    
    
    
    </body>
    </html>

    连接数据库

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
        <%@ page import="java.sql.*" import="java.util.*"%>
    <!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>留言板</title>
    </head>
    <body>
    
    
    
    <%
    String email=(String)session.getAttribute("email");
    String liuyan=(String)session.getAttribute("liuyan");
    
    Connection con=null;
    
    try {
        //连接数据库
        Class.forName("oracle.jdbc.driver.OracleDriver");
        String strUrl="jdbc:oracle:thin:@localhost:1521:ORCL";        
        con=DriverManager.getConnection(strUrl,"test","test");
    //添加到数据库
    PreparedStatement ps=con.prepareStatement("insert into text values(?,?)"); ps.setString(1, email); ps.setString(2, liuyan); ps.executeUpdate(); out.print("留言添加成功!"+"<br>"); //显示所有留言 Statement st=con.createStatement(); //查询数据库,并遍历显示 ResultSet rs=st.executeQuery("select * from text"); while(rs.next()) { String youxiang=rs.getString("email"); String text=rs.getString("neirong"); out.print("邮箱为"+youxiang+"的留言内容为"+text+"<br>"); } %> <% ps.close(); st.close(); rs.close(); } catch (Exception e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } finally { if(con!=null) { try { con.close(); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } } %> <%-- 您的邮箱地址是: <%=email %> <br> 您的留言内容是: <%=liuyan %> --%> </body> </html>

    运行结果:

  • 相关阅读:
    Maven pom.xml中的元素modules、parent、properties以及import
    基于SpringBoot搭建应用开发框架(一) —— 基础架构
    Spring Boot项目使用Eclipse进行断点调试Debug
    eclipse 运行springboot项目
    如何在eclipse中使用mvn clean install
    https://www.cnblogs.com/zy-jiayou/p/7661415.html
    SpringBoot系列三:SpringBoot基本概念(统一父 pom 管理、SpringBoot 代码测试、启动注解分析、配置访问路径、使用内置对象、项目打包发布)
    WebJars are client-side web libraries (e.g. jQuery & Bootstrap) packaged into JAR (Java Archive) files
    在EF中使用Expression自动生成p=>new Entity(){X="",Y="",..}格式的Lambda表达式灵活实现按需更新
    EF跨库查询,DataBaseFirst下的解决方案
  • 原文地址:https://www.cnblogs.com/miss123/p/5620690.html
Copyright © 2011-2022 走看看