警告:StandardWrapperValve [jsp]:PWC1406:Servlet jsp的Servlet.service()抛出异常java.lang.NullPointerException

时间:2012-11-16 08:26:56

标签: java jsp javabeans

我一直在非常简单的JSP / Bean页面上收到此警告, 我正在考试,我无法超越这个。

有人能指出我的愚蠢吗?

<html>
    <head>

        <title>JSP Page</title>
    </head>
    <h1>Enter Details!</h1>
    <body>
        <form action="Display.jsp" method="post">

            <center>
                Enter Name :<input type="text" name="Name"/><br/>
                Etv :<input type="radio" name="Channel" value="Etv" /><br/>
                Mnet :<input type="radio" name="Channel" value="Mnet" /><br/>
                Mtv :<input type="radio" name="Channel" value="Mtv" /><br/>
                FTV :<input type="radio" name="Channel" value="FTV" /><br/>
                Blue :<input type="checkbox" name="Blue" value="1" /><br/>
                Yellow :<input type="checkbox" name="Yellow" value="1" /><br/>
                Green :<input type="checkbox" name="Green" value="1" /><br/>
                Red :<input type="checkbox" name="Red" value="1" /><br/>
                <br/>
                <br/>

                <input type="submit" value="Submit" />
            </center>
        </form>

    </body>
</html>

我的Javabean:

package Beans;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.beans.*;
import java.io.Serializable;

/**
 *
 * @author Ross
 */
public class NewBean implements Serializable {

    private String Name;
    private String Channel;
    private int Blue;
    private int Yellow;
    private int Green;
    private int Red ;

    public NewBean() {

    }

     public NewBean(String tName,String tChannel,int tBlue,int tYellow,int tGreen,int tRed) {

    Name=tName;
    Channel=tChannel;
    Blue=tBlue;
    Yellow=tYellow;
    Green=tGreen;
    Red=tRed;
    }

    public String getName(){
      return this.Name;
    }
    public String getChannel(){
      return this.Channel;
    }
    public int getBlue(){
      return this.Blue;
    }
    public int getYellow(){
      return this.Yellow;
    }
    public int getGreen(){
      return this.Green;
    }
    public int getRed(){
      return this.Red;
    }
    public void setName(String tName){
      this.Name = tName;
    }
    public void setChannel(String tChannel){
      this.Channel = tChannel;
    }
    public void setBlue(int tBlue){
      this.Blue = tBlue;
    }
    public void setYellow(int tYellow){
      this.Yellow = tYellow;
    }
    public void setGreen(int tGreen){
      this.Green = tGreen;
    }
    public void setRed(int tRed){
      this.Red = tRed;
    }
}

我的JSP显示javabean:

<html>
    <head>

        <title>Display</title>
    </head>
    <body>
        <h1>Result</h1>
        <center>
            <jsp:useBean id="NewBean"class="Beans.NewBean">

                <jsp:setProperty name="index" property="Name" param="Name"/>
                <jsp:setProperty name="index" property="Channel" param="Channel"/>
                <jsp:setProperty name="index" property="Blue" param="Blue"/>
                <jsp:setProperty name="index" property="Yellow" param="Yellow"/>
                <jsp:setProperty name="index" property="Green" param="Green"/>
                <jsp:setProperty name="index" property="Red" param="Red"/>
            </jsp:useBean>
            <b>Displayed.</b>
             <jsp:getProperty name="index" property="Name"/>
             <jsp:getProperty name="index" property="Channel"/>
             <jsp:getProperty name="index" property="Blue"/>
             <jsp:getProperty name="index" property="Yellow"/>
             <jsp:getProperty name="index" property="Green"/>
             <jsp:getProperty name="index" property="Red"/>
        </center>

    </body>
</html>

1 个答案:

答案 0 :(得分:0)

您应该遵循变量的java命名约定(camel case)。即。

//private String Name;
private String name;

public void setName(String tName){
  //this.Name = tName;
  this.name = tName;
}

应该用小写属性“name”引用:

<!-- jsp:setProperty name="index" property="Name" param="Name"/ -->
<jsp:setProperty name="index" property="name" param="Name"/>