java吧 关注:1,191,978贴子:12,605,368
  • 8回复贴,共1

Tomcat上显示空指针异常!求大神帮忙解决!!!

只看楼主收藏回复




IP属地:广东1楼2016-03-08 16:35回复
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Enumeration;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class ShowParameters extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html;charset=gd2312");
    PrintWriter out = response.getWriter();
    String title ="Reading All Request Parameters";
    out.println("<html><head><title>读取所有参数</title></head>"
    + "<body BGCOLOR='#FDF5E6'>\n" + "<H1 ALIGN=CENTER>" +title
    + "</H1>\n" + "<TABLE BORDER=1 ALIGN=CENTER>\n"
    + "<tr BGCOLOR=\"#FFADOO\">\n"
    + "<th>Parameter Name<TH>Parameter Value(s)");
    Enumeration paramNames =request.getParameterNames();
    while (paramNames.hasMoreElements()){
    String paramName = (String) paramNames.nextElement();
    out.print("<tr><td>" +paramName +"\n<td>");
    String[] paramValues =request.getParameterValues(paramName);
    if(paramValues.length ==1){
    String paramValue =paramValues[0];
    if(paramValue.length() == 0)
    out.println("<I>No Value </I>");
    else
    out.println(paramValue);
    }else{
    out.println("<UL>");
    for (int i =0;i<paramValues.length;i++){
    out.println("<LI>" + paramValues[i]);
    }
    out.println("</UL>");
    }
    }
    }
    }


    IP属地:广东2楼2016-03-08 16:36
    回复
      小弟菜鸟真心求教了


      IP属地:广东3楼2016-03-08 16:37
      回复
        为自己顶了!!!!


        IP属地:广东4楼2016-03-08 16:48
        回复
          看不清,解决空指针的问题,先把空对象找到,然后结合业务分析为何为空,是否允许为空,最后再解决问题


          IP属地:湖南来自Android客户端5楼2016-03-08 17:01
          收起回复