<%@ page contentType="text/html; charset=gb2312" %>
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">
//查詢該用戶所有的訂單信息
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){
}
}
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對像設置有問題