Demo.
jsp
<jsp:useBean id="Bean1" class="[Link]">
<jsp:setProperty name = "Bean1" property ="name" value ="Zara"/>
<jsp:getProperty name = "Bean1" property = "name"/>
</jsp:useBean>
[Link]
package Bean;
public class Students {
public Students() {
private String name;
public String getName() {
return name;
public void setName(String name) {
[Link] = name;
}
[Link]
package javaskool;
import [Link].*;
import [Link].*;
import [Link].*;
public class Customer implements Serializable
{
private String custID;
private String custName;
private int storeCust;
public String getCustID() {
return custID;
}
public void setCustID(String custID) {
[Link] = custID;
}
public String getCustName() {
return custName;
}
public void setCustName(String custName) {
[Link] = custName;
}
public int setStoreCust()
{
try{
[Link]("[Link]");
Connection
con=[Link]("jdbc:mysql://localhost:3306/db1","root","root");
PreparedStatement pstmt=null;
String query=null;
query="insert into Customer values(?,?)";
pstmt=[Link](query);
[Link](1,custID);
[Link](2,custName);
int i=[Link]();
[Link]=i;
}
catch(Exception e)
{
}
return storeCust;
}
}
[Link]
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="[Link].*" %>
<%@ page import="[Link]" %>
<html>
<head>
<title>JSP and JavaBean</title>
<%-- create an instance of Customer class --%>
<jsp:useBean id="Customer" class="[Link]">
<jsp:setProperty name = "Customer" property ="custID" value ="C12"/>
<jsp:setProperty name = "Customer" property ="custName" value ="Archana"/>
<jsp:getProperty name = "Customer" property = "custID"/>
<jsp:getProperty name = "Customer" property = "custName"/>
</jsp:useBean>
</head>
<body>
<%
int x=[Link]();
if(x>=1)
{
%>
<jsp:forward page="[Link]" />
<%
}
else
{
%>
<jsp:forward page="[Link]" />
<%
}
%>
</body>
</html>
[Link]
<%
[Link]("<html>");
[Link]("<Body>");
[Link]("<B><center>Thank you for purchasing with us....</center><b><br><br>");
[Link]("</Body>");
[Link]("</html>");
%>
[Link]
<%
[Link]("<html>");
[Link]("<Body>");
[Link]("<B><center>Sorry, Your Transaction is failed....</center><b><br><br>");
[Link]("</Body>");
[Link]("</html>");
%>