在jsp bean中找不到符号错误

在jsp bean中找不到符号错误,jsp,symbols,Jsp,Symbols,谢谢你阅读这个问题 下面的代码 我正在尝试让jsp与数据库一起工作。数据库当前已部分填充,我正在尝试将此信息返回到浏览器并打印出来 不幸的是,当我尝试这样做时,我得到一个错误,即编译器在我尝试在newjsp.jsp中调用getStudentList()的行中找不到符号“studentData” 我从一个朋友的项目中复制了newjsp中的代码,该项目运行良好 我希望你能帮忙 谢谢 工厂182 *********StudentBean.java****** package my.b

谢谢你阅读这个问题

下面的代码

我正在尝试让jsp与数据库一起工作。数据库当前已部分填充,我正在尝试将此信息返回到浏览器并打印出来

不幸的是,当我尝试这样做时,我得到一个错误,即编译器在我尝试在newjsp.jsp中调用getStudentList()的行中找不到符号“studentData”

我从一个朋友的项目中复制了newjsp中的代码,该项目运行良好

我希望你能帮忙

谢谢

工厂182

*********StudentBean.java******

         package my.beans;


         public class StudentBean {


                 private String firstName;
                 private String lastName;
                 private String comment;
                 private String email;

                 public StudentBean(){

                 }

                 // get/set for First Name
                 public void setFirstName(String firstName) {
                         this.firstName = firstName;
                 }
                 public String getFirstName(){
                         return firstName;
                 }

                 // get/set for Last Name
                 public void setLastName(String lastName) {
                         this.lastName = lastName;
                 }
                 public String getLastName(){
                         return lastName;
                 }

                 // get/set for comment
                 public void setComment(String comment) {
                         this.comment = comment;
                 }
                 public String getComment(){
                         return comment;
                 }

                 // get/set for Email
                 public void setEmail(String email) {
                         this.email = email;
                 }
                 public String getEmail(){
                         return email;
                 }
         }
         package my.beans;

         import java.sql.SQLException;
         import javax.sql.rowset.CachedRowSet;
         import java.util.ArrayList;
         import com.sun.rowset.CachedRowSetImpl; // CachedRowSet implementation

         public class StudentDataBean {

            private CachedRowSet rowSet;

            // construct TitlesBean object
            public StudentDataBean() throws Exception
            {
               // load the MySQL driver
               Class.forName( "com.mysql.jdbc.Driver" );

               // specify properties of CachedRowSet
               rowSet = new CachedRowSetImpl();
               rowSet.setUrl( "jdbc:mysql://localhost:3306/test" );
               rowSet.setUsername( "root" );
               rowSet.setPassword( "" );

                   // obtain list of titles
               rowSet.setCommand(
                  "SELECT firstName, lastName, email, comment FROM guests" );
               rowSet.execute();
            } // end StudentDataBean constructor

            // return an ArrayList of StudnetBeans
            public ArrayList<StudentBean> getStudentList() throws SQLException
            {
               ArrayList<StudentBean> studentList = new ArrayList<StudentBean>();

               rowSet.beforeFirst(); // move cursor before the first row

               // get row data
               while ( rowSet.next() )
               {
                  StudentBean student = new StudentBean();

                  student.setFirstName( rowSet.getString( 1 ) );
                  student.setLastName( rowSet.getString( 2 ) );
                  student.setEmail( rowSet.getString( 3 ) );
                  student.setComment( rowSet.getString( 4 ) );
                  studentList.add( student );
               } // end while

               return studentList;
            } // end method getStudentList

            // insert a Student in student database
         public void addStudent( StudentBean student ) throws SQLException
         {
         rowSet.moveToInsertRow(); // move cursor to the insert row

          // update the three columns of the insert row
         rowSet.updateString( 1, student.getFirstName() );
         rowSet.updateString( 2, student.getLastName() );
         rowSet.updateString( 3, student.getEmail() );
         rowSet.updateString( 4, student.getComment() );
         rowSet.insertRow(); // insert row to rowSet
         rowSet.moveToCurrentRow(); // move cursor to the current row
         rowSet.acceptChanges(); // propagate changes to database
         } // end method addStudent
    } // end class StudentDataBean
   <%@page import="java.util.ArrayList"%>
   <%@page contentType="text/html" pageEncoding="UTF-8"%>
   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

   <%@ page import="java.util.*" %>
   <%@ page import="my.beans.StudentDataBean"%>
   <%@ page import="my.beans.StudentBean"%>
   <jsp:useBean id="studentData" scope="request" class="my.beans.StudentDataBean"/>
   <html>
     <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
         <title>Words View</title>
           <style type="text/css">
           table, tr, td, th
           {
                text-algn: center;
                font-size: .9em;
                border: 3px groove;
                padding: 3px;
                background-color: #eee9e9;
           }
     </style>
     </head>
     <body>
     <h1>Student List</h1>
     <table border="1">
        <tr>
            <th>
                <h4>Email</h4>
            </th>
            </tr>
                <%
                    ArrayList<StudentBean> studentList = studentData.getStudentList();
                    Iterator studentListIterator = studentList.iterator();
                    StudentBean student;

                    while (studentListIterator.hasNext()){
                        student = (StudentBean) studentListIterator.next();
                %>
            <tr>
                <td><%= student.getEmail()%></td>

            </tr>
            <% }
            %>
     </table>
     </body>
     </html>
******StudentDataBean.java*********

         package my.beans;


         public class StudentBean {


                 private String firstName;
                 private String lastName;
                 private String comment;
                 private String email;

                 public StudentBean(){

                 }

                 // get/set for First Name
                 public void setFirstName(String firstName) {
                         this.firstName = firstName;
                 }
                 public String getFirstName(){
                         return firstName;
                 }

                 // get/set for Last Name
                 public void setLastName(String lastName) {
                         this.lastName = lastName;
                 }
                 public String getLastName(){
                         return lastName;
                 }

                 // get/set for comment
                 public void setComment(String comment) {
                         this.comment = comment;
                 }
                 public String getComment(){
                         return comment;
                 }

                 // get/set for Email
                 public void setEmail(String email) {
                         this.email = email;
                 }
                 public String getEmail(){
                         return email;
                 }
         }
         package my.beans;

         import java.sql.SQLException;
         import javax.sql.rowset.CachedRowSet;
         import java.util.ArrayList;
         import com.sun.rowset.CachedRowSetImpl; // CachedRowSet implementation

         public class StudentDataBean {

            private CachedRowSet rowSet;

            // construct TitlesBean object
            public StudentDataBean() throws Exception
            {
               // load the MySQL driver
               Class.forName( "com.mysql.jdbc.Driver" );

               // specify properties of CachedRowSet
               rowSet = new CachedRowSetImpl();
               rowSet.setUrl( "jdbc:mysql://localhost:3306/test" );
               rowSet.setUsername( "root" );
               rowSet.setPassword( "" );

                   // obtain list of titles
               rowSet.setCommand(
                  "SELECT firstName, lastName, email, comment FROM guests" );
               rowSet.execute();
            } // end StudentDataBean constructor

            // return an ArrayList of StudnetBeans
            public ArrayList<StudentBean> getStudentList() throws SQLException
            {
               ArrayList<StudentBean> studentList = new ArrayList<StudentBean>();

               rowSet.beforeFirst(); // move cursor before the first row

               // get row data
               while ( rowSet.next() )
               {
                  StudentBean student = new StudentBean();

                  student.setFirstName( rowSet.getString( 1 ) );
                  student.setLastName( rowSet.getString( 2 ) );
                  student.setEmail( rowSet.getString( 3 ) );
                  student.setComment( rowSet.getString( 4 ) );
                  studentList.add( student );
               } // end while

               return studentList;
            } // end method getStudentList

            // insert a Student in student database
         public void addStudent( StudentBean student ) throws SQLException
         {
         rowSet.moveToInsertRow(); // move cursor to the insert row

          // update the three columns of the insert row
         rowSet.updateString( 1, student.getFirstName() );
         rowSet.updateString( 2, student.getLastName() );
         rowSet.updateString( 3, student.getEmail() );
         rowSet.updateString( 4, student.getComment() );
         rowSet.insertRow(); // insert row to rowSet
         rowSet.moveToCurrentRow(); // move cursor to the current row
         rowSet.acceptChanges(); // propagate changes to database
         } // end method addStudent
    } // end class StudentDataBean
   <%@page import="java.util.ArrayList"%>
   <%@page contentType="text/html" pageEncoding="UTF-8"%>
   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

   <%@ page import="java.util.*" %>
   <%@ page import="my.beans.StudentDataBean"%>
   <%@ page import="my.beans.StudentBean"%>
   <jsp:useBean id="studentData" scope="request" class="my.beans.StudentDataBean"/>
   <html>
     <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
         <title>Words View</title>
           <style type="text/css">
           table, tr, td, th
           {
                text-algn: center;
                font-size: .9em;
                border: 3px groove;
                padding: 3px;
                background-color: #eee9e9;
           }
     </style>
     </head>
     <body>
     <h1>Student List</h1>
     <table border="1">
        <tr>
            <th>
                <h4>Email</h4>
            </th>
            </tr>
                <%
                    ArrayList<StudentBean> studentList = studentData.getStudentList();
                    Iterator studentListIterator = studentList.iterator();
                    StudentBean student;

                    while (studentListIterator.hasNext()){
                        student = (StudentBean) studentListIterator.next();
                %>
            <tr>
                <td><%= student.getEmail()%></td>

            </tr>
            <% }
            %>
     </table>
     </body>
     </html>
打包my.beans;
导入java.sql.SQLException;
导入javax.sql.rowset.CachedRowSet;
导入java.util.ArrayList;
导入com.sun.rowset.CachedRowSetImpl;//CachedRowSet实现
公共班级学生数据库{
私有CachedRowSet行集;
//构造标题bean对象
public StudentDataBean()引发异常
{
//加载MySQL驱动程序
Class.forName(“com.mysql.jdbc.Driver”);
//指定CachedRowSet的属性
行集=新的CachedRowSetImpl();
setUrl(“jdbc:mysql://localhost:3306/test" );
rowSet.setUsername(“根”);
rowSet.setPassword(“”);
//获取标题列表
rowSet.setCommand(
“选择名字、姓氏、电子邮件、客人评论”);
rowSet.execute();
}//end StudentDataBean构造函数
//返回StudnetBeans的ArrayList
公共ArrayList getStudentList()引发SQLException
{
ArrayList studentList=新建ArrayList();
rowSet.beforeFirst();//将光标移到第一行之前
//获取行数据
while(rowSet.next())
{
StudentBean student=newstudentbean();
student.setFirstName(rowSet.getString(1));
student.setLastName(rowSet.getString(2));
setEmail(rowSet.getString(3));
setComment(rowSet.getString(4));
学生列表。添加(学生);
}//结束时
返回学生名单;
}//结束方法getStudentList
//在学生数据库中插入学生
public void addStudent(StudentBean student)引发SQLException
{
rowSet.moveToInsertRow();//将光标移动到插入行
//更新插入行的三列
updateString(1,student.getFirstName());
updateString(2,student.getLastName());
updateString(3,student.getEmail());
updateString(4,student.getComment());
rowSet.insertRow();//将行插入到行集
rowSet.moveToCurrentRow();//将光标移动到当前行
rowSet.acceptChanges();//将更改传播到数据库
}//结束方法addStudent
}//结束类StudentDataBean
*****newjsp.jsp********

         package my.beans;


         public class StudentBean {


                 private String firstName;
                 private String lastName;
                 private String comment;
                 private String email;

                 public StudentBean(){

                 }

                 // get/set for First Name
                 public void setFirstName(String firstName) {
                         this.firstName = firstName;
                 }
                 public String getFirstName(){
                         return firstName;
                 }

                 // get/set for Last Name
                 public void setLastName(String lastName) {
                         this.lastName = lastName;
                 }
                 public String getLastName(){
                         return lastName;
                 }

                 // get/set for comment
                 public void setComment(String comment) {
                         this.comment = comment;
                 }
                 public String getComment(){
                         return comment;
                 }

                 // get/set for Email
                 public void setEmail(String email) {
                         this.email = email;
                 }
                 public String getEmail(){
                         return email;
                 }
         }
         package my.beans;

         import java.sql.SQLException;
         import javax.sql.rowset.CachedRowSet;
         import java.util.ArrayList;
         import com.sun.rowset.CachedRowSetImpl; // CachedRowSet implementation

         public class StudentDataBean {

            private CachedRowSet rowSet;

            // construct TitlesBean object
            public StudentDataBean() throws Exception
            {
               // load the MySQL driver
               Class.forName( "com.mysql.jdbc.Driver" );

               // specify properties of CachedRowSet
               rowSet = new CachedRowSetImpl();
               rowSet.setUrl( "jdbc:mysql://localhost:3306/test" );
               rowSet.setUsername( "root" );
               rowSet.setPassword( "" );

                   // obtain list of titles
               rowSet.setCommand(
                  "SELECT firstName, lastName, email, comment FROM guests" );
               rowSet.execute();
            } // end StudentDataBean constructor

            // return an ArrayList of StudnetBeans
            public ArrayList<StudentBean> getStudentList() throws SQLException
            {
               ArrayList<StudentBean> studentList = new ArrayList<StudentBean>();

               rowSet.beforeFirst(); // move cursor before the first row

               // get row data
               while ( rowSet.next() )
               {
                  StudentBean student = new StudentBean();

                  student.setFirstName( rowSet.getString( 1 ) );
                  student.setLastName( rowSet.getString( 2 ) );
                  student.setEmail( rowSet.getString( 3 ) );
                  student.setComment( rowSet.getString( 4 ) );
                  studentList.add( student );
               } // end while

               return studentList;
            } // end method getStudentList

            // insert a Student in student database
         public void addStudent( StudentBean student ) throws SQLException
         {
         rowSet.moveToInsertRow(); // move cursor to the insert row

          // update the three columns of the insert row
         rowSet.updateString( 1, student.getFirstName() );
         rowSet.updateString( 2, student.getLastName() );
         rowSet.updateString( 3, student.getEmail() );
         rowSet.updateString( 4, student.getComment() );
         rowSet.insertRow(); // insert row to rowSet
         rowSet.moveToCurrentRow(); // move cursor to the current row
         rowSet.acceptChanges(); // propagate changes to database
         } // end method addStudent
    } // end class StudentDataBean
   <%@page import="java.util.ArrayList"%>
   <%@page contentType="text/html" pageEncoding="UTF-8"%>
   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

   <%@ page import="java.util.*" %>
   <%@ page import="my.beans.StudentDataBean"%>
   <%@ page import="my.beans.StudentBean"%>
   <jsp:useBean id="studentData" scope="request" class="my.beans.StudentDataBean"/>
   <html>
     <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
         <title>Words View</title>
           <style type="text/css">
           table, tr, td, th
           {
                text-algn: center;
                font-size: .9em;
                border: 3px groove;
                padding: 3px;
                background-color: #eee9e9;
           }
     </style>
     </head>
     <body>
     <h1>Student List</h1>
     <table border="1">
        <tr>
            <th>
                <h4>Email</h4>
            </th>
            </tr>
                <%
                    ArrayList<StudentBean> studentList = studentData.getStudentList();
                    Iterator studentListIterator = studentList.iterator();
                    StudentBean student;

                    while (studentListIterator.hasNext()){
                        student = (StudentBean) studentListIterator.next();
                %>
            <tr>
                <td><%= student.getEmail()%></td>

            </tr>
            <% }
            %>
     </table>
     </body>
     </html>

词语观
表,tr,td,th
{
文本algn:中心;
字体大小:.9em;
边框:3px凹槽;
填充:3倍;
背景色:#eee9e9;
}
学生名单
电子邮件

可能是ide错误,请重新启动netbeans。(如果你正在使用netbeans…否则天知道。)爱汤姆xx可能是ide错误,重新启动netbeans。(如果你使用的是netbeans…否则天知道。)爱汤姆xx是的,不知道是什么错误。在netbeans中一定有什么东西。哦,现在工作得很好。谢谢:)XXXYeah,不确定是什么错误。在netbeans中一定有什么东西。哦,现在工作得很好。谢谢:)XXX