2

我不断收到这个警告,在一个非常简单的 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>
4

1 回答 1

0

您应该遵循变量的 java 命名约定(驼峰式)。IE

//private String Name;
private String name;

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

应由小写属性“名称”引用:

<!-- jsp:setProperty name="index" property="Name" param="Name"/ -->
<jsp:setProperty name="index" property="name" param="Name"/>
于 2012-11-16T08:57:37.820 回答