程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> javaweb-jsp頁面從數據庫撈數據,報了一個好奇怪的錯誤

javaweb-jsp頁面從數據庫撈數據,報了一個好奇怪的錯誤

編輯:編程綜合問答
jsp頁面從數據庫撈數據,報了一個好奇怪的錯誤

查詢jsp:

<%@ page contentType="text/html; charset=gb2312" %>

Book Query


輸入用戶名:


display頁面:

1<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">




Queryinfor


用戶名:
快遞單號:
發貨地:
收貨地:
重量:
價格:

javaDAO:

//查詢該用戶所有的訂單信息
public ProductBean searchinfom(String username){
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rst = null;
ProductBean product = new ProductBean();
try{
conn = dataSource.getConnection();
pstmt = conn.prepareStatement("SELECT * FROM userproduct WHERE username=?");
pstmt.setString(1,username);
rst = pstmt.executeQuery();
if(rst.next()){
product.setUsername(rst.getString("username"));
product.setProduct_id(rst.getString("product_id"));
product.setFaddress(rst.getString("faddress"));
product.setSaddress(rst.getString("saddress"));
product.setWeight(rst.getDouble("weight"));
product.setPrice(rst.getDouble("price"));
return product;
}else{
return null;
}
}catch(SQLException se){
return null;
}finally{
try{
conn.close();
}catch(SQLException se){
}
}

servlet:

package com.demo;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bean.ProductBean;
import com.bean.ProductDao;

public class QueryInformServlet extends HttpServlet{
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
String username = request.getParameter("username");
ProductDao productdao = new ProductDao();
ProductBean product = productdao.searchinfom(username);

    //if(product!=null){
      request.getSession().setAttribute("username",username);
      RequestDispatcher view = request.getRequestDispatcher("/displayinform.jsp");
      view.forward(request, response);
    //}else{
      //RequestDispatcher view = request.getRequestDispatcher("/error.jsp");
      //view.forward(request, response);
    //}
  } 
}

最佳回答:


jsp代碼不完整啊,是不是dto對像設置有問題

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved