jsp测试程序

作者 :
免费
  • 正文
  • JSP输出语句:
    
    <%
    out.print("<h1>Hello,Wmhp.<br><br>wmphp.com</h1>");
    %>
    
    javascript跳转语句:
    
    <script>location="/phpinfo.php";</script>
    
    MySQL测试:
    
    <%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
    <%@ page import="java.sql.Connection" %>
    <%@ page import="java.sql.DriverManager" %>
    <%@ page import="java.sql.SQLException" %>
    <%@ page import="java.sql.Statement" %>
    <%@ page import="java.sql.PreparedStatement" %>
    <%@ page import="java.sql.ResultSet" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>mysql测试</title>
    
    </head>
    <body>
    mysql测试 看到以下信息说明mysql连接正常
    <br><br>
    <%
    //此进行连接数据库
    String url="jdbc:mysql://127.0.0.1:3306/test"; //test为数据库名称
    String dbuser="root"; //数据库账户
    String dbpwd="root"; //数据库密码
    try
    {
    Class.forName("com.mysql.jdbc.Driver"); //加载驱动 JspStudy
    }
    catch (ClassNotFoundException e)
    {
    e.printStackTrace();
    }
    //取得数据库连接conn JspStudy
    Connection conn=DriverManager.getConnection(url, dbuser, dbpwd);;
    
    PreparedStatement ps=null;
    ResultSet rs=null;
    String username="";
    String pwd="";
    String name="";
    try
    {
    String sql="select id,username,password,name from users";
    ps = conn.prepareStatement(sql);
    rs = ps.executeQuery();
    while(rs.next())
    {
    username=rs.getString(2);
    pwd=rs.getString(3);
    name=rs.getString(4);
    out.println("账户:"+username+"   密码:"+pwd+"   姓名:"+name+"<br>");
    }
    }
    catch (SQLException e)
    {
    e.printStackTrace();
    }
    finally
    {
    try
    {
    if(rs!=null)
    rs.close();
    }
    catch (SQLException e)
    {
    e.printStackTrace();
    }
    finally
    {
    try
    {
    if(ps!=null)
    ps.close();
    }
    catch (SQLException e)
    {
    e.printStackTrace();
    }
    finally
    {
    try
    {
    if(conn!=null)
    conn.close();
    }
    catch (SQLException e)
    {
    e.printStackTrace();
    }
    }
    }
    }
    %>
    </body>
    </html>
    
     
    

     

    END
    如本资源侵犯了您的权益,请联系投诉邮箱admin@wmphp.com进行举报!我们将在收到邮件的1个小时内处理完毕。 本站仅为平台,发布的资源均为用户投稿或转载!所有资源仅供参考学习使用,请在下载后的24小时内删除,禁止商用! Wmphp.com(完美源码)助力正版,如您有自己的原创产品,可以联系客服投稿,代理出售! Wmphp.com(完美源码)客服QQ:136882447 Wmphp.com(完美源码)商务电话(仅对企业客户/个人用户):15120086569 (微信同步) 请注意:本站不提供任何免费的技术咨询服务,为了节约时间,下载前 请确认自己会技术
    完美源码 » jsp测试程序
    3467+

    本站勉强运行

    3649+

    用户总数

    689+

    资源总数

    0+

    今日更新

    2024-3-11

    最后更新时间