source file name: student.html
<html>
<head>
<title>Student Information </title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
</head>
<body>
<form action="http://localhost:8080/JspWebApplication/studinfo.jsp" method="post" >
Enter Student's Name : <input type="text" name="t1" size='50' />
<br >
Enter Student's Rollno : <input type="number" name="t2" />
<br>
Enter Students Address : <input type="text" name="t3" size='50' />
<br>
<input type="submit" value="Submit" />
</form>
</body>
</html>
output:
source file name: studinfo.jsp
<%! int rollno; %>
<%! String name, address; %>
<%
rollno=Integer.parseInt(request.getParameter("t2"));
name=request.getParameter("t1");
address=request.getParameter("t3");
out.println("<h2>given student information <br> Roll Number : "+rollno+"Name: "+name+" Address: "+address);
%>
<jsp:useBean id="stud" class="mybeans.student" />
<br> <h1> Student's information from Bean </h1>
<h2>
Roll Number is:
<jsp:setProperty name="stud" property="rollno" value="<%=rollno %>" />
<jsp:getProperty name="stud" property="rollno" />
<br> Name is:
<jsp:setProperty name="stud" property="name" value="<%=name %>" />
<jsp:getProperty name="stud" property="name" />
<br> Address is:
<jsp:setProperty name="stud" property="address" value="<%=address %>" />
<jsp:getProperty name="stud" property="address" />
</h2>
output:
/source file name: student.java
Java Bean class
package mybeans;
/**
*
* @author Indian
*/
public class student
{
int rollno;
String name,add;
public student()
{}
public void setrollno(int m)
{
rollno=m;
}
public int getrollno()
{
return rollno;
}
public void setname(String nm)
{
name=nm;
}
public String getname()
{
return name;
}
public void setaddress(String ad)
{
add=ad;
}
public String getaddress()
{
return add;
}
}
0 Comments
Post a Comment