MyException - 我的异常网
当前位置:我的异常网» Java Web开发 » TOMCAT 出错,又来麻烦大家了.该怎么解决

TOMCAT 出错,又来麻烦大家了.该怎么解决(4)

www.MyException.Cn  网友分享于:2013-12-28  浏览:10次

代码的风格不好,开始的时候,一定要养成好的编程风格!要把视图和控制,还有模型分开,不要把jsp写入很多java代码,我帮你看了一下,修改如下:
<%@ page contentType= "text/html; charset=gb2312 "%>
<%@ page import= "java.sql.* "%>
<%@ page import= "java.util.* "%>
<%@ page import= "java.util.Date "%>
<%@ page import= "java.text.* "%>
<%@ include file= "inc/conn.jsp "%>
<%
//request.setCharacterEncoding( "GB2312 ") ;
%>
<html>
<head>
<title> </title>
</head>
<body>

<%
String name=null;
name = (String)session.getAttribute( "name ");
if(name== " "||name==null)
{
out.print( "你必须登录才行噢 ");
%>
<center>
<a href= "register.jsp "> 注册 </A>
<a href= "login.jsp "> 登录 </a>
</center>
<%
}
else
{
out.print( "Hi, "+ name + " 欢迎您回来! ");

%>

<a href= "logout.jsp "> 注销 </a>
<hr />
<br/>
<br/>
<table width= "760 " border=1 cellspacing=0 bordercolordark=#CCCCCC bordercolor=#ffffff align= "center ">
<tr align= "center ">

<td width= "6% "> ID </td>
<td width= "10% "> 姓名 </td>
<td width= "9% "> 妮称 </td>
<td width= "7% "> 密码 </td>
<td width= "15% "> Email </td>
<td width= "5% "> 性别 </td>
<td width= "32% "> 登陆时间 </td>
<td width= "16% "> IP </td>

</tr>


<%
try
{
Connection con = DriverManager.getConnection( "DatabaseURL ");
Statement stmt = con.createStatement();
String sql= "select * from staff order by id DESC ";
ResultSet rs=stmt.executeQuery(sql);

int intPageSize; //一页显示的记录数
int intRowCount; //记录总数
int intPageCount; //总页数
int intPage; //待显示页码
String strPage;
int i;

//设置一页显示的记录数
intPageSize = 10;

//取得待显示页码
strPage = request.getParameter( "pages ");
if(strPage==null){
//表明在QueryString中没有page这一个参数,此时显示第一页数据
intPage = 1;
}
else
{
//将字符串转换成整型
intPage = Integer.parseInt(strPage);
if(intPage <1){ intPage = 1;}
}
//获取记录总数
rs.last();
intRowCount = rs.getRow();
//计算总页数
intPageCount =(intRowCount+intPageSize-1) / intPageSize;

//调整待显示的页码
if(intPage> intPageCount) intPage = intPageCount;
if(intPageCount> 0){
//将记录指针定位到待显示页的第一条记录上
rs.absolute((intPage-1) * intPageSize+1);
//显示数据
i = 0;

//if (rs.next()){
while(i < intPageSize && !rs.isAfterLast()){


int id=rs.getInt( "id ");
String uuser=rs.getString( "name ");
String nicheng=rs.getString( "nickname ");
String pass=rs.getString( "password ");
String email=rs.getString( "email ");
String sex=rs.getString( "sex ");
String time=rs.getString( "lasttime ");
String ip=rs.getString( "ip ");

%>

<tr align= "center ">
<td> <%=id%> </td>
<td> <%=uuser%> </td>
<td> <%=nicheng%> </td>
<td> <%=pass%> </td>
<td> <%=email%> </td>

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有