为什么我的数据库更新了,网页没有更新的?

protectxp 2002-10-31 07:05:18
//AddBook.html
<html>
<body>
<form action="AddBook.jsp" method="post">
book id:<br>
<input type=text name="id" size=10><br>
book name:<br>
<input type=text name="name" size=50><br>
book description:<br>
<input type=text name="des" size=100><br>
book pirce:<br>
<input type=text name="price" size=50><br>
book quantity:<br>
<input type=text name="qty" size=50><br>
<input type=hidden name="operation" value="insert">
<input type=submit name=submit value=submit>
<input type=reset name=reset value=reset>
</form>
</body>
</html>

//AddBook.jsp
<%@ page contentType="text/html" import="book.*,java.util.*" %>
<html>
<body>
<%
int errType=0;
String id=request.getParameter("id") ;
String name=request.getParameter("name") ;
String des=request.getParameter("des") ;
float price=Float.parseFloat(request.getParameter("price"));
int qty=Integer.parseInt(request.getParameter("qty"));
int leftqty=qty;
String operation=request.getParameter("operation") ;
System.out.println(id);
System.out.println(name);
System.out.println(des);
System.out.println(price);
System.out.println(qty);
System.out.println(leftqty);
Book book = new Book(id,name,des,price,qty,leftqty);
System.out.println(book.operateBook(operation));
%>
<jsp:include page="AllBook.jsp">All Book</a>
</body>
</html>

//Book.class
package book;

import java.sql.*;
import java.util.*;

public class Book
{

public Book()
{
}

public Book(String id,String name,String des,float price,int qty,int leftqty)
{
this.id =id;
this.name =name;
this.des =des;
this.price =price;
this.qty =qty;
this.leftqty =leftqty;
}

public String operateBook(String operation)
{
String strReturn="";
if (operation.equals("") || operation=="")
return "what operation will u select !!";
if (operation.equals("insert"))
{
sql="insert into book values (\'" + this.id + "\',";
sql=sql+ "\'" + this.name + "\',";
sql=sql+ "\'" + this.des + "\',";
sql=sql+ "\'" + this.qty + "\',";
sql=sql+ "\'" + this.leftqty + "\',";
sql=sql+ "\'" + this.price + "\')";
}
else if (operation.equals("update"))
{
sql="update book set name=\'" + this.name +"\',";
sql =sql + "des=\'" + this.des + "\',";
sql =sql + "qty=\'" + this.qty + "\',";
sql =sql + "leftqty=\'" + this.leftqty + "\',";
sql =sql + "price=\'" + this.price + "\' " ;
sql =sql + "where id=\'" + this.id + "\'";
}
else if (operation.equals("delete"))
{
sql ="delete from book where id = \'" + this.id + "\'";
}
else if (operation.equals("select") )
{
if (this.id.equals("") ||this.id =="")
;
else
sql = "select id,name,des,price,qty,leftqty from book where id =\'" + this.id + "\'";
}
ConDB conDB=new ConDB();
conDB.connectToDB() ;
this.con =conDB.getCon() ;
this.st =conDB.getSt() ;
try
{
if (operation.equals("select") )
{
rs=st.executeQuery(sql) ;
while(rs.next() )
{
this.id=rs.getString("id") ;
this.name =rs.getString("name") ;
this.des =rs.getString("des") ;
this.price =rs.getFloat("price") ;
this.qty =rs.getInt("qty") ;
}
strReturn=sql+ " and find " +this.name ;
}
else
strReturn= sql + st.executeUpdate(sql);
conDB.Close() ;
return strReturn;
}
catch (Exception e)
{
return "fail " + sql ;
}
}

public void setId(String id)
{
this.id =id;
}

public String getId()
{
return this.id ;
}

public void setName(String name)
{
this.name =name;
}

public String getName()
{
return this.name ;
}

public void setDes(String des)
{
this.des =des;
}

public String getDes()
{
return this.des ;
}

public void setPrice(float price)
{
this.price =price;
}

public float getPrice()
{
return this.price ;
}

public void setQty(int qty)
{
this.qty =qty;
}

public int getQty()
{
return this.qty ;
}

public void setLeftQty(int leftqty)
{
this.leftqty =leftqty;
}

public int getLeftQty()
{
return this.leftqty ;
}

private String id ="";
private String name="";
private String des="";
private int qty=0;
private int leftqty=0;
private float price =0;
private Connection con=null;
private Statement st=null;
private String sql="";
private ResultSet rs=null;

//conDB.class
package book;

import java.util.*;
import java.sql.*;

public class ConDB
{

public ConDB()
{
}

public String connectToDB()
{
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver" ) ;
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://MARUSHO-SERVER1;DatabaseName=test","sa","123456") ;
st=con.createStatement() ;
return "success connecting to DB!!!";
}
catch(Exception e)
{
return "fail connecting to DB!!" + e.getMessage() ;
}
}

public String Close()
{
try
{
if (st!=null)
st.close() ;
if (con!=null)
con.close() ;
return "success disconnecting toDB!!!";
}
catch(Exception e)
{
return "fail disconnecting to DB !!"+ e.getMessage() ;
}
}

public Connection getCon()
{
return this.con;
}

public Statement getSt()
{
return this.st;
}
private Connection con=null;
private Statement st=null;
}

//AllBook.jsp

<%@ page contentType="text/html" import="book.*,java.util.*" %>
<html>
<jsp:useBean id="Catalog" scope="session" class="book.Catalog" />
<body>
<table border="1" >
<form method="get">
<input type=hidden name=action value=0>
<tr bgcolor="#9999FF">
<td><b></b></td>
<td><b>book name</b></td>
<td><b>book description</b></td>
<td><b>book price</b></td>
<td><b>book quantity</b></td>
<td><b>left book</b></td>
</tr>
<%
Vector books=Catalog.getBooks() ;
for (int i=0;i<books.size() ;i++)
{
Book book=(Book)books.elementAt(i);
%>
<tr>
<td><input type=checkbox name=bookid value=<%=book.getId() %> <%= book.getLeftQty()>0 ?"":"disabled"%>></td>
<td><%=book.getName() %></td>
<td><%=book.getDes() %></td>
<td><%=book.getPrice() %></td>
<td><%=book.getQty() %></td>
<td><%=book.getLeftQty() %></td>
<%
}
%>
</tr>
<tr>
<td colspan=6>
<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset"></td>
<br>
</form>
</table>
</body>
</html>
我在JB7(安装好后没有修改配置)中运行了AddBook.jsp后数据库中更新了,在AllBook.jsp中没有更新的?
...全文
47 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zxhong 2002-11-01
  • 打赏
  • 举报
回复
应该是缓存问题
删除
\tomcat\work下的文件
esunboy 2002-11-01
  • 打赏
  • 举报
回复
有时候需要删除它的_jsp目录下编译过的文件
scriptskychen 2002-10-31
  • 打赏
  • 举报
回复
这是jsp的老问题了,你把tomcat重启,把网页的缓冲删除,再打开一个新的网页试试吧,应该就可以了!
slase 2002-10-31
  • 打赏
  • 举报
回复
估计服务器段有缓存吧,没有在数据库更新后再去查询,还用了原来的页面,看看tomcat的配置是不是能改一下。
meizz 2002-10-31
  • 打赏
  • 举报
回复
你将网页设置成不在客户端缓存试试.

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧