package com.v512.webproject2;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SurveyServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public SurveyServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* 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 {
doPost(request,response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @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 doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
request.setCharacterEncoding("utf-8");
out.println("姓名:" +request.getParameter("name")+"<br>");
out.println("Email:" +request.getParameter("email")+"<br>");
out.println("age:" +request.getParameter("age")+"<br>");
out.println("编程时间:" +request.getParameter("bt")+"<br>");
out.println("操作系统:");
String os[]=request.getParameterValues("os");
out.println("<ul>");
for(int i=0;i<os.length;i++)
{out.println("<li>"+os[i]+"</li>");
}
out.println("</ul><br>" );
out.println("编程语言:");
String lanuage[]=request.getParameterValues("lanuage");
out.println("<ul>");
for(int i=0;i<lanuage.length;i++)
{out.println("<li>"+lanuage[i]+"</li>");
}
out.println("</ul><br>" );
out.println(request.getParameter("comment")+"<br>");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
out.println("<ul>");
for(int i=0;i<os.length;i++)
{out.println("<li>"+os[i]+"</li>");
}
String lanuage[]=request.getParameterValues("lanuage");
out.println("<ul>");
for(int i=0;i<lanuage.length;i++)
{out.println("<li>"+lanuage[i]+"</li>");
}
这两个地方有错误,你换成下面的代码就可以了:
String os[]=request.getParameterValues("os");
out.println("<ul>");
if(os != null )
{
for(int i=0;i<os.length;i++)
{out.println("<li>"+os[i]+"</li>");
}
}
String lanuage[]=request.getParameterValues("lanuage");
out.println("<ul>");
if(lanuage != null)
{
for(int i=0;i<lanuage.length;i++)
{out.println("<li>"+lanuage[i]+"</li>");
}
}
这样就可以了
首先找到发生异常的那行,然后寻找逐步向上找源头。如果没有必要查找源头,可以直接绕过它。譬如:
1,List<String>books=BooKDAO.findAll();
2,intsize=books.size();
如果第2行发生空指针异常了,知道books肯定为null了,这时查找BookDAO.的findAll方法,如果findAll()方法又调用了其他的方法,可以继续查下去。如果没有业务需要,可以直接写成:
List<String>books=BooKDAO.findAll();
intsize=0;
if(books!=null){
size=books.size();
}
或者
List<String>books=BooKDAO.findAll();
intsize=0;
try{
size=books.size();
}catch(NullpointerException){
size=0;或者不写或者打印错误
}
/iknow-pic.cdn.bcebos.com/8694a4c27d1ed21b27f786aba06eddc451da3f45"target="_blank"title="点击查看大图"class="ikqb_img_alink">/iknow-pic.cdn.bcebos.com/8694a4c27d1ed21b27f786aba06eddc451da3f45?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto"esrc=""/>
扩展资料
最重要的类是Object(它是类层次结构的根)和Class(它的实例表示正在运行的应用程序中的类)。把基本类型的值当成一个对象来表示通常很有必要。包装器类Boolean、Character、Integer、Long、Float和Double就是用于这个目的。
类Math提供了常用的数学函数,比如正弦、余弦和平方根。类似地,类String和StringBuffer提供了常用的字符串操作。
类ClassLoader、Process、Runtime、SecurityManager和System提供了管理类的动态加载、外部进程创建、主机环境查询(比如时间)和安全策略实施等“系统操作”。
类Throwable包含了可能由throw语句抛出的对象(§14.16)。Throwable的子类表示错误和异常。
参考资料:/baike.baidu.com/item/java.lang/5179788"target="_blank"title="java.lang-百度百科">java.lang-百度百科