提交请求的时候,执行下面的doget的时候出现了错误:
程序代码如下:import java.io.*;
import java.awt.*;
import javax.servlet.*;
import javax.servlet.http.*;public class ShowScoreClass extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    {
        response.setContentType("text/html");        PrintWriter out = response.getWriter();
        ScoreNode[] myScore=new ScoreNode[4];
        myScore[0].SetScoreNode("1103101119","刘博",100,80,50);
        myScore[1].SetScoreNode("1103101132","张元元",50,80,50);
        myScore[2].SetScoreNode("1103101134","朱成广",45,58,92);
        myScore[3].SetScoreNode("1103101120","马守文",70,80,90);        String userno=request.getParameter("StudNo");         int i=0;
     for(;i<4;i++)
if((myScore[i].getSno()).equals(userno))
  break;
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Hello World!</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Hello "+myScore[i].getName()+"World!</h1>");
        out.println("</body>");
        out.println("</html>");
  }}class ScoreNode
{
String Sno;
String Name;
int EmScore;
int databaseScore;
int ProScore;
ScoreNode()
{
Sno="";
Name="";
EmScore=0;
databaseScore=0;
ProScore=0;
}
void SetScoreNode(String ValueSno,String ValueName,int ValueEm,int DatabaseScore,int PromScore)
{
        Sno=ValueSno;
Name=ValueName;
EmScore=ValueEm;
databaseScore=DatabaseScore;
ProScore=PromScore;
}
String getSno(){
return Sno;
}
String getName(){
return Name;
}
int getEnScore(){
return databaseScore;
}
int getProScore(){
return ProScore;
}
}
错误页面提示信息:
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception java.lang.NullPointerException
ShowScoreClass.doGet(ShowScoreClass.java:17)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.27 logs.
--------------------------------------------------------------------------------Apache Tomcat/5.0.27
我的XML部署描述文件中相关部分:

 <servlet>
    <servlet-name>ShowScore</servlet-name>
    <servlet-class>ShowScoreClass</servlet-class>
    </servlet>
    <!--启动定制URL-->
    <servlet-mapping>
      <servlet-name>ShowScore</servlet-name>
      <url-pattern>/ShowScore</url-pattern>
      </servlet-mapping>

HTML中相关代码:
................
<form action="ShowScore" method="get">
<table border="3" bgcolor="#CECA92" bordercolor="value" rules="all" cellpadding="5"
cellspacing="2" width="400" align="left" background="4.jpg">
<tr>
<td>Student number:</td>
<td><input type="text" name="StudNo"></td>
</tr>
由于刚刚学SEVLET ,不知道问题出在哪里了?
请高手赐教
感激不尽
~~~~~~~~~~~~~~~~~~`````

解决方案 »

  1.   

    空指针异常,<form action="ShowScore" method="get">对应的bean没有配置吧?配置以下xml的bean
      

  2.   

    不好意思,没有看清,<url-pattern>/ShowScore</url-pattern>是不对的吧!改为 <url-pattern>/ShowScore/*</url-pattern>或者<url-pattern>*.do</url-pattern>
      

  3.   

    <servlet-name>ShowScore</servlet-name>
        <servlet-class>ShowScoreClass</servlet-class>这也有问题吧?配置为servlet有的Actionservlet,你自己在检查一下吧!
      

  4.   

    很感谢楼上的兄弟
    但是问题不是SEVLET配置的问题
    我终于解决了这个问题
    是因为我的类有一点问题
    ScoreNode[] myScore=new ScoreNode[4];
    //主要问题出现在下面
    因为我的ScoreNode类没有默认的构造函数,所以这样的定义运行到这里的时候,其实类还没有长生,所以执行到myScore[0].SetScoreNode("1103101119","刘博",100,80,50);
    的时候产生异常,因为myScore[0]对象还没有产生,就不能调用他的非构造函数的其他方法
    要是添加了一句:
    for(int i=0;i<4;i++)
      myScore[i]=new myScore();
    程序就能够顺利执行了
                    myScore[1].SetScoreNode("1103101132","张元元",50,80,50);
            myScore[2].SetScoreNode("1103101134","朱成广",45,58,92);
            myScore[3].SetScoreNode("1103101120","马守文",70,80,90);多谢haodp兄弟的热心帮助,和一楼和二楼兄弟
    再次表示感谢