I am new to jsp and beans.I tried to make a small bean example but getting a jsp compile time error as follows:
Student.jsp:1:1: Needed class "find_record.StudentBean" is not found.
^
Student.jsp:4:34: The bean type "find_record.StudentBean" was not found.
<jsp:useBean id="findbean" class="find_record.StudentBean" scope="session" />
^-----------------------^
Student.jsp:5:23: This bean name does not exist.
<jsp:setProperty name="findbean" property="rollno" />
i have a Student.jsp to call StudentBean.java but getting that error following are the code: Student.jsp
<html>
<body >
<jsp:useBean id="findbean" class="find_record.StudentBean" scope="session" />
<jsp:setProperty name="findbean" property="rollno" />
<%
String status=findbean.findRecord();
if(status.equals("success"));
%>
<jsp:include page="Success.jsp" />
<% else %>
<jsp:include page="Error.jsp" />
</body>
</html>
StudentBean.java
//StudentBean,java
package find_record;
import java.sql.*;
public class StudentBean{
String name ,rollno,grade;
int marks;
public StudentBean(){}
public void setName(String name){
this.name=name;
}
public void setRollno(String rollno){
this.rollno=rollno;
}
public void setMarks(int marks){
this.marks=marks;
}
public void setGrade(String grade){
this.grade=grade;
}
public String getName(){
return(name);
}
public String getRollno(){
return(rollno);
}
public int getMarks(){
return(marks);
}
public String getGrade(){
return(grade);
}
public String findRecord(){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","user","password");
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("Select * from student where rollno="+rollno);
int c=0;
while(rs.next()){
System.out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3)+" "+rs.getString(4));
c++;
}
if(c>0)
{
System.out.println("success");
return("success");
}
conn.close();
throw new Exception("record not found");
}catch(Exception e){
System.out.println(e.getMessage());
return("no record found");
}
}
}