JSP网页制作
- 提问者网友:玫瑰园
- 2021-04-13 00:16
- 五星知识达人网友:杯酒困英雄
- 2021-04-13 01:28
简单的就有
<%--
Document : checkDB
Created on : 2009-11-1, 23:21:46
Author : Administrator
--%>
<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
<%@page import="java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
" http://www.w3.org/TR/html4/loose.dtd">
<%
int dipage = 1;
String pages = request.getParameter("dipage");
if (pages == null) {
pages = "1";
}
try {
dipage = Integer.parseInt(pages);
} catch (Exception e) {
dipage = 1;
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=ming", "min", "123");
Statement stmt = con.createStatement();
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery("select * from liuyan order by time desc");
int countRecord = 0;
int i = 0;
int countPageRecord = 0;
int countPage = 1;
countPageRecord = 5;
rs.last();
countRecord = rs.getRow();
if (countRecord / countPageRecord == 0) {
countPage = countRecord / countPageRecord;
} else {
countPage = countRecord / countPageRecord + 1;
}
if ((dipage - 1) * countPageRecord == 0) {
rs.beforeFirst();
} else {
rs.absolute((dipage - 1) * countPageRecord);
}
%>
<% while (rs.next()) {%>
<p> <table border="0">
<tbody>
<tr>
<td><img src="d:\我的文档\桌面\tian\image\9809.jpg"/>
</td>
<td > </td>
<td>主题:<%=rs.getString(4)%></td>
</tr>
<tr>
<td>姓名:<%=rs.getString(2)%></td>
<td > </td>
<td > 内容:</td>
</tr>
<tr>
<td>E-mail:<%=rs.getString(3)%></td>
<td > </td>
<td width="150"><%=rs.getString(5)%></td>
</tr>
</tbody>
</table></p>
--------------------------------------------------------
<%
i++;
if (i >= countPageRecord) {
break;
}
}
out.print("共" + countRecord + "条记录,共" + countPage + "页,当前第" + dipage + "页,每页" + countPageRecord + "条记录");
if (dipage == 1); else {
out.print("<a href=showly.jsp?dipage=1>首页</a>,");
out.print("<a href=showly.jsp?dipage=" + (dipage - 1) + ">上一页</a>,");
}
if (dipage == countPage) {
;
} else {
out.print("<a href=showly.jsp?dipage=" + (dipage + 1) + ">下一页</a>,");
out.print("<a href=showly.jsp?dipage=" + countPage + ">末页</a>");
}
out.print("<tr>");
rs.close();
stmt.close();
con.close();
} catch (Exception e) {
out.println("数据库异常");
}
%>
<form name="liuyanban" action="mas_saves.jsp" method="POST">
<table border="0">
<tbody>
<tr>
<td>留言人:</td>
<td><input type="text" name="lname" value="" /></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input type="text" name="Email" value="" /></td>
</tr>
<tr>
<td>留言主题:</td>
<td><input type="text" name="zhuti" value="" /></td>
</tr>
<tr>
<td>留言信息:</td>
<td></td>
</tr>
</tbody>
</table>
<textarea name="neirong" rows="5" cols="35">
</textarea>
<table border="0">
<tbody>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> <input type="submit" value="提交" name="tijiao" /></td>
<td> <input type="button" value="关闭" name="close" /></td>
</tr>
</tbody>
</table>
</form>
<%
out.print("<form action=check.jsp method=post>");
out.print("<input type=submit value=返回></form>");%>
</body>
</html>
mas_saves.jsp
<%--
Document : mas_saves
Created on : 2009-11-5, 23:03:00
Author : Administrator
--%>
<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
<%@page import="java.util.Date" %>
<!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>
<%!
public String codeToString(String str)
{
String s=str;
try{
byte tempB[]=s.getBytes("ISO-8859-1");
s=new String(tempB);
return s;
}
catch(Exception e){
return s;
}
}
%>
<%
request.setCharacterEncoding("UTF-8");
try{
String name=request.getParameter("lname");
String Email=request.getParameter("Email");
String zhuti=request.getParameter("zhuti");
String neirong=request.getParameter("neirong");
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=ming", "min", "123");
Statement stmt=con.createStatement();
stmt.execute("insert into liuyan (time,lname,email,tops,neirong)"+ "values(getdate(),'"+name+"','"+Email+"','"+zhuti+"','"+neirong+"')");
out.println("留言成功");
response.setHeader("refresh","1;url=showly.jsp");
con.close();
}
catch(SQLException e )
{
out.println("数据库异常");
}
%>
</body>
</html>
- 1楼网友:鱼芗
- 2021-04-13 02:25