J2EE Programming

Hands On No. 9 : <jsp:useBean> in JSP

Source Code of Form(index.jsp)
                                

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>

<form method="post" action="viewData.jsp">
<input type="text" name="firstname"><input type="text" name="lastname"><input type="submit">
</form>
</body>
</html>

Source Code of viewData.jsp
                                

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<jsp:useBean id="c" class="sourcef.StringAdd" />
<%
String a = request.getParameter("firstname");
String b = request.getParameter("lastname");
String sname = c.sadd(a,b);
out.print(sname);
%>
</body>
</html>

Source Code of Bean
                                

package sourcef;

public class StringAdd {
public String sadd(String fname,String lname)
{
return(fname+ " "+lname);
}
}