Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Cia-6

 JavaBeans:-

1. Design a Student Bean class with getter/setters for the Student


details like first name, last name and age; Access the above
bean class in JSP.

 Newhtml.html
<html>
<body>
<form method="post" action="index.jsp">
First Name:<input type="text" name="firstname"/>
Last Name:<input type="text" name="lastname"/>
Age:<input type="text" name="Age"/>
USN:<input type="text" name="usn"/>
Email_ID:<input type="text" name="email_id"/>
Course:<input type="text" name="course"/>
<input type="submit" value="go"/>
</form>
</body>
</html>

 Index.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title>Getter and Setter method</title>
</head>
<body>
<center>
<p> GET AND SET EXAMPLES </p>
<jsp:useBean id="students" class="p1.student">
<jsp:setProperty name="students" property="firstName"
value="KHYATI"/>
<jsp:setProperty name="students" property="lastName"
value="PARIKH"/>
<jsp:setProperty name="students" property="age"
value='22'/>
<jsp:setProperty name="students" property="usn"
value='18MSRIT010'/>
<jsp:setProperty name="students" property="email_id"
value='[email protected]'/>
<jsp:setProperty name="students" property="course"
value='MSCIT'/>
<p> First Name: <jsp:getProperty name="students"
property="firstName"/> </p>
<p> Last Name: <jsp:getProperty name="students"
property="lastName"/>
</p>
<p>Age:<jsp:getProperty name="students" property="age"/>
</p>
<p>USN:<jsp:getProperty name="students"
property="usn"/>
</p>
<p>EMail_ID:<jsp:getProperty name="students"
property="email_id"/>
</p>
<p>Course:<jsp:getProperty name="students" property="course"/>
</p>
</jsp:useBean>
</center>
</body>
</html>

 Student.java
package p1;
import java.beans.*;
import java.io.Serializable;
public class student implements java.io.Serializable
{
private String firstName = null;
private String lastName = null;
private int age = 0;
private String usn = null;
private String email_id = null;
private String course = null;

public student() {
}
public String getFirstName(){
return firstName;
}
public String getLastName(){
return lastName;
}
public int getAge(){
return age;
}
public String getUsn(){
return usn;
}
public String getEmail_id(){
return email_id;
}
public String getCourse(){
return course;
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public void setLastName(String lastName)
{
this.lastName = lastName;
}
public void setAge(int age)
{
this.age = age;
}
public void setUsn(String usn)
{
this.usn = usn;
}
public void setEmail_id(String email_id)
{
this.email_id = email_id;
}
public void setCourse(String course)
{
this.course = course;
}
}

You might also like