请各路大神帮小弟看一看,为什么数据传不过来!急急急········
小z啊 2016-02-02 09:22:12 public class JavaBean {
public static final int PAGE_SIZE=15;
private int id;
private String name;
private String password;
private String sex;
private int age;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public static int getPageSize() {
return PAGE_SIZE;
}
}
/**
* 分页查询所有商品信息
* @param page 页数
* @return List<Product>
* */
public ArrayList<JavaBean> find(int page){
ArrayList<JavaBean> list=new ArrayList<JavaBean>();
String sql="SELECT TOP "+JavaBean.PAGE_SIZE+" * FROM userTable WHERE ID NOT IN (SELECT TOP "+(page-1) * JavaBean.PAGE_SIZE+" ID FROM userTable ORDER BY ID DESC) ORDER BY ID DESC";
try{
pre=con.prepareStatement(sql);
//ps.setInt(1,Product.PAGE_SIZE);
//ps.setInt(2,(page-1) * Product.PAGE_SIZE);
rs=pre.executeQuery();
while(rs.next()){
JavaBean jBean=new JavaBean();
jBean.setId(rs.getInt("id"));
jBean.setName(rs.getString("name"));
jBean.setPassword(rs.getString("password"));
jBean.setSex(rs.getString("sex"));
jBean.setAge(rs.getInt("age"));
list.add(jBean);
}
if(rs!=null)
{
rs.close();
}
if(pre!=null)
{
pre.close();
}
if(con!=null)
{
con.close();
}
}catch(SQLException e){
e.printStackTrace();
}
return list;
}
/**
* 查询总记录数
* @return 总记录数
* */
public int findCount(){
int count=0;
String sql="select count(*) from userTable";
try{
pre=con.prepareStatement(sql);
rs=pre.executeQuery(); //查询并获取ResultSet
if(rs.next()){ //光标向后移动,并判断是否有效
count=rs.getInt(1); //对总记录数赋值
}
rs.close(); //关闭ResultSet
con.close();
}catch(SQLException e){
e.printStackTrace();
}
return count;
}
public class FindServlet extends HttpServlet{
/**
*
*/
private static final long serialVersionUID = 1L;
public void doPost(HttpServletRequest request,
HttpServletResponse response)throws ServletException,
IOException{
doGet(request,response);
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)throws ServletException,
IOException{
response.setContentType("text/html;");
int currPage=1;
if(request.getParameter("page")!=null){
currPage = Integer.parseInt(request.getParameter("page"));
}
Conn dao=new Conn();
List<JavaBean> list=dao.find(currPage);
request.setAttribute("list", list);
int pages;
int count = dao.findCount();
if(count % JavaBean.PAGE_SIZE == 0){
pages = count / JavaBean.PAGE_SIZE;
}else{
pages = count / JavaBean.PAGE_SIZE+1;
}
StringBuffer sb=new StringBuffer();
for(int i=1;i<pages; i++){
if(i == currPage){
sb.append("["+ i +"]");
}else{
sb.append("<a href='FindServlet?page="+i+"'>"+i+"</a>");
}
sb.append(" ");
}
request.setAttribute("bar", sb.toString());
request.getRequestDispatcher("SearchList.jsp").forward(request, response);
}
}
JSP页面
<body>
<!--
<jsp:useBean id="sBean" class="com.xshgl.conn.Conn"></jsp:useBean>
<jsp:useBean id="jBean" class="com.xshgl.model.JavaBean"></jsp:useBean>
-->
<center>
<font color=red size=72><b>学生信息如下:</b></font>
<hr>
<form name="form1" action="Search" method="post">
<table width="500">
<tr align="left">
<td><b>学生信息查询(按ID查询):</b><input type="text" name="id"><input type="submit" value="查询"></td>
</tr>
</table>
</form>
</center>
<form name="form" action="Insert.jsp" method="post">
<center>
<table border="1" bgcolor="#ffffff" width="500px" height="100px" bordercolor="#OOAAAA">
<tr>
<td align="center"><font size="5"><b>ID</b></font></td>
<td align="center"><font size="5"><b>姓名</b></font></td>
<td align="center"><font size="5"><b>密码</b></font></td>
<td align="center"><font size="5"><b>性别</b></font></td>
<td align="center"><font size="5"><b>年龄</b></font></td>
<td align="center"><font size="5"><b>操 作</b></font></td>
</tr>
<%
@SuppressWarnings("unchecked")
List<JavaBean> list=(List<JavaBean>)request.getAttribute("list");
if(list==null||list.size()<1)
{
out.print("没有数据!");
}else{
for(JavaBean p:list){
%>
<tr>
<td align="center"><b><%=p.getId()%></b></td>
<td align="center"><%=p.getName()%></td>
<td align="center"><%=p.getPassword()%></td>
<td align="center"><%=p.getSex()%></td>
<td align="center"><%=p.getAge()%></td>
<td align="center">
<a href="Delete?id=<%=jBean.getId() %>"><input type="button" value="删除" onclick="javascript:return del();"></a>
<a href="SearchById?id=<%=jBean.getId() %>"><input type="button" value="修改"></a>
</td>
</tr>
<%
}
}
%>
<tr>
<td align="center" colspan="6">
<%=request.getAttribute("bar") %>
</td>
</tr>
</table><br>
<input type="submit" value="添加学生信息">
<a href="login.jsp"><input type="button" value="返回登录页面"></a>
</center>
</form>
</body>
运行结果
信息: Unable to locate configuration files of the name struts.xml, skipping
2016-2-2 9:18:21 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts.xml]
2016-2-2 9:18:21 org.apache.catalina.loader.WebappClassLoader validateJarFile
信息: validateJarFile(D:\Users\MyEclipse 10\Tomcat-6.0\webapps\Text.myeclipse.bak\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
2016-2-2 9:18:21 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-default.xml]
2016-2-2 9:18:21 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts-plugin.xml]
2016-2-2 9:18:21 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Unable to locate configuration files of the name struts.xml, skipping
2016-2-2 9:18:21 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Parsing configuration file [struts.xml]
2016-2-2 9:18:22 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2016-2-2 9:18:22 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2016-2-2 9:18:22 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/15 config=null
2016-2-2 9:18:22 org.apache.catalina.startup.Catalina start
信息: Server startup in 10680 ms
数据库连接成功!!!
就这样而已 也没报错 还没找出问题 请大神指点