java大神帮我解决下网页搜索框的问题

这是serlet:
package sjbsjb;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import sjb.db.*;
import sjb.entity.*;

public class search extends HttpServlet {

/**

  • The doGet method of the servlet.
    *
  • This method is called when a form has its tag value method equals to get.
  • @param request the request send by the client to the server
  • @param response the response send by the server to the client
  • @throws ServletException if an error occurred
  • @throws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { dbtools dt = new dbtools();// 实例化数据库连接工具 String server = "localhost"; String dbname = "qimo"; String username = "root"; String pwd = "aaaa"; try { dt.setConnection(server, dbname, username, pwd); String keyword= request.getParameter("text"); byte[] keyword1=keyword.getBytes("ISO-8859-1"); keyword =new String(keyword1); System.out.print(" keyword="+ keyword); List phoneList = new ArrayList(); { String sql ="SELECT * FROM view_phonedetail where Name like '%"+keyword+"%' or name like '%"+keyword+"%'; "; System.out.print("sql="+sql); ResultSet rs = dt.executeQuery(sql);

while (rs.next()) {
phone pd=new phone();
pd.setId(rs.getInt("id"));
pd.setName(rs.getString("name"));
pd.setPrice(rs.getString("price"));

pd.setZhongjie(rs.getString("Zhongjie"));
pd.setTupian(rs.getString("Tupian"));

System.out.println(rs.getString("name"));
System.out.println(rs.getString("price"));
System.out.println(rs.getInt("id"));
System.out.println(rs.getString("zhongjie"));
System.out.println(rs.getString("tupian"));
phoneList.add(pd);

}

}

request.setAttribute("phoneList", phoneList);
request.getRequestDispatcher("search.jsp").forward(request, response);

} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
dt.closeAll();
}

}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}

}

这是JSP:

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@page import="sjb.entity.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">







phoneList = (List) request.getAttribute("phoneList"); phone pd=new phone(); for(int i=0;i

共搜索到 条结果

价格:¥
店铺价格:¥
简介:


错误提示:
HTTP Status 500 - java.lang.NullPointerException

type Exception report

message java.lang.NullPointerException

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:430)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

root cause

java.lang.NullPointerException
org.apache.jsp.search_jsp._jspService(search_jsp.java:103)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.37 logs.
Apache Tomcat/6.0.37

1个回答

忍着半天看完了你贴的代码,但是图也没有,解释一下你想干啥,错误是空指针,有东西没取到,,
phoneList = (List) request.getAttribute("phoneList"); phone pd=new phone(); for(int i=0;i
共搜索到 条结果

我这看到的是上面的情况,,少了点代码吧。。。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问