远程PC上的数字格式异常:可能是什么原因?

时间:2015-03-07 10:55:44

标签: java servlets numberformatexception

发生了奇怪的事情。

使用url:http://localhost:8080/Football/InsertTeam?p1_name=hkh&p2_name=klhjk&p3_name%E2%80%A6er=79&p4_name=aa&p5_name=ss&p6_name=hh&p7_name=dd&p8_name=ee&p9_name=kk&p10_name=ll&p11_name=bb&p1_number=1&p2_number=3&p3_number=9&p4_number=5&p6_number=7&p7_number=8&p8_number=9&p9_number=8098&p10_number=7979&p11_number=79&teams=brazil+vs+germany

调用以下servlet时

在我的机器上,它工作正常,但它在其他机器上给出以下异常:

enter image description here

除了端口号(在我的8081上运行,在另一个上运行8080),一切都是一样的。(两者都运行tomcat)

这种奇怪发生的原因是什么?

public class InsertTeam extends HttpServlet {


@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String p1Name = request.getParameter("p1_name");
    String p2Name = request.getParameter("p2_name");
    String p3Name = request.getParameter("p3_name");
    String p4Name = request.getParameter("p4_name");
    String p5Name = request.getParameter("p5_name");
    String p6Name = request.getParameter("p6_name");
    String p7Name = request.getParameter("p7_name");
    String p8Name = request.getParameter("p8_name");
    String p9Name = request.getParameter("p9_name");
    String p10Name = request.getParameter("p10_name");
    String p11Name = request.getParameter("p11_name");

    int p1Number = Integer.parseInt(request.getParameter("p1_number")); // GIVES AN ERROR HERE
    int p2Number = Integer.parseInt(request.getParameter("p2_number"));
    int p3Number = Integer.parseInt(request.getParameter("p3_number"));
    int p4Number = Integer.parseInt(request.getParameter("p4_number"));
    int p5Number = Integer.parseInt(request.getParameter("p5_number"));
    int p6Number = Integer.parseInt(request.getParameter("p6_number"));
    int p7Number = Integer.parseInt(request.getParameter("p7_number"));
    int p8Number = Integer.parseInt(request.getParameter("p8_number"));
    int p9Number = Integer.parseInt(request.getParameter("p9_number"));
    int p10Number =Integer.parseInt(request.getParameter("p10_number"));
    int p11Number = Integer.parseInt(request.getParameter("p11_number"));

    String teams = request.getParameter("teams");

    Team teamMember1 = new Team();
    teamMember1.setpName(p1Name); teamMember1.setpNumber(p1Number); teamMember1.setTeams(teams);

    Team teamMember2 = new Team();
    teamMember2.setpName(p2Name); teamMember2.setpNumber(p2Number); teamMember2.setTeams(teams);

    Team teamMember3 = new Team();
    teamMember3.setpName(p3Name); teamMember3.setpNumber(p3Number); teamMember3.setTeams(teams);

    Team teamMember4 = new Team();
    teamMember4.setpName(p4Name); teamMember4.setpNumber(p4Number); teamMember4.setTeams(teams);

    Team teamMember5 = new Team();
    teamMember5.setpName(p5Name); teamMember5.setpNumber(p5Number); teamMember5.setTeams(teams);

    Team teamMember6 = new Team();
    teamMember6.setpName(p6Name); teamMember6.setpNumber(p6Number); teamMember6.setTeams(teams);

    Team teamMember7 = new Team();
    teamMember7.setpName(p7Name); teamMember7.setpNumber(p7Number); teamMember7.setTeams(teams);

    Team teamMember8 = new Team();
    teamMember8.setpName(p8Name); teamMember8.setpNumber(p8Number); teamMember8.setTeams(teams);

    Team teamMember9 = new Team();
    teamMember9.setpName(p9Name); teamMember9.setpNumber(p9Number); teamMember9.setTeams(teams);

    Team teamMember10 = new Team();
    teamMember10.setpName(p10Name); teamMember10.setpNumber(p10Number); teamMember10.setTeams(teams);

    Team teamMember11 = new Team();
    teamMember11.setpName(p11Name); teamMember11.setpNumber(p11Number); teamMember11.setTeams(teams);

    Configuration configuration = new Configuration().configure();
    SessionFactory sessFact = configuration.buildSessionFactory();
    Session sess = sessFact.openSession();
    Transaction trans = sess.beginTransaction();

    sess.save(teamMember1);
    sess.save(teamMember2);
    sess.save(teamMember3);
    sess.save(teamMember4);
    sess.save(teamMember5);
    sess.save(teamMember6);
    sess.save(teamMember7);
    sess.save(teamMember8);
    sess.save(teamMember9);
    sess.save(teamMember10);
    sess.save(teamMember11);

    trans.commit();
    sess.close();

}

}

PS:其他机器是远程的,很难调试。

1 个答案:

答案 0 :(得分:1)

没有p3_number是您的网址,这意味着以下内容会引发异常:

int p3Number = Integer.parseInt(request.getParameter("p3_number"));