📄 index.jsp
字号:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!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=gb2312">
<title>注册登录系统首页</title>
<link rel="stylesheet" href="register.css" type="text/css"/>
</head>
<%
session.setAttribute("user","jack");
String UserId = (String)session.getAttribute("user");
if(UserId == null || UserId == "")
response.sendRedirect("login.jsp");
String product_name = "";
float price;
String description = "";
Connection con = null;
Statement sm = null;
ResultSet rs = null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost/mydb";
con = DriverManager.getConnection(url,"root","12345");
sm = con.createStatement();
rs = sm.executeQuery("select * from products");
}catch(Exception e){
e.printStackTrace();
}
%>
<body>
<table width="80%" align="center">
<tr>
<td class="title"> 用户注册登录系统==<span class="title1">产品展示</span>==</td>
<td style="width:150; height:20; vertical-align:middle; text-align:center;"><%=UserId%> 您好! <a href="login.jsp">登录</a> | <a href="logout.jsp">注销</a></td>
</tr>
</table>
<hr align="center" width="75%" color="#990000" size="1"/>
<table width="80%" align="center">
<tr><td height="5" colspan="2"></td></tr>
<%
while(rs.next()){
product_name = rs.getString("PRODUCT_NAME");
price = rs.getFloat("PRICE");
description = rs.getString("DESCRIPTION");
%>
<tr>
<td> 产品名称:<%=product_name%></td><td width="40%"> 报价:<span style="color:#FF0000; font-style:italic;"><%=price%></span></td>
</tr>
<tr>
<td colspan="2"> 描述:<%=description%></td>
</tr>
<tr><td height="5" colspan="2"><hr size="3" width="10%"/></td></tr>
<%
}
%>
</table>
<div align="center" class="tail">2006==本公司版权拥有</div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -