Displaying errors in jsp page
Tuesday, March 2, 2010
now get the attribute from request from servlet.and display errors
here we have created two objects. one is for displaying empty fields when we run jsp page first time .
and second one is for displaying errors .
if you have any doubts post your comment below
we did not do any thing just get the request attribute from servlet and display errors using bean methods
now run insertupdate.jsp page
<%--
Document : index
Author : Jagadeesh
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@page import="model.UserBean" %>
<% UserBean bean;
bean = new UserBean();
//get request from servlet if data is invalid
if(request.getAttribute("error")!=null)
{
bean = (UserBean)request.getAttribute("error");
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form method="post" action="ControllerServlet">
<CENTER>
<TABLE border="0"width="600px">
<TR>
<TD width="150px">Name:</TD>
<TD>
<INPUT TYPE="text" NAME="userName" value="<%=bean.getUserName()%>">
</TD>
<TD width="350px">
<font color="red"><%=bean.getUserNameError()%> </font>
</TD>
</TR>
<TR>
<TD width="150px">Date Of Birth:</TD>
<TD>
<INPUT TYPE="text" NAME="dateOfBirth" value="<%=bean.getDateOfBirth()%>">
</TD>
<TD>
<font color="red"><%=bean.getDateOfBirthError()%> </font>
</TD>
</TR>
<TR>
<TD width="150px">E-Mail</TD>
<TD>
<INPUT TYPE="text" NAME="email" value="<%=bean.getEmail()%>">
</TD>
<TD>
<font color="red"><%=bean.getEmailError()%> </font>
</TD>
</TR>
<TR>
<TD width="150px">Phone no:</TD>
<TD>
<INPUT TYPE="text" NAME="phoneNo" value="<%=bean.getPhoneNo()%>">
</TD>
<TD>
<font color="red"><%=bean.getPhoneNoError()%> </font>
</TD>
</TR>
<TR>
<TD colspan="2" align="center">
<INPUT TYPE="submit" value="<%=bean.getAction()%>" name="action">
</TD>
<TD>
</TD>
</TR>
</TABLE>
</CENTER>
</form>
</body>
</html>
here we have created two objects. one is for displaying empty fields when we run jsp page first time .
and second one is for displaying errors .
if you have any doubts post your comment below
we did not do any thing just get the request attribute from servlet and display errors using bean methods
now run insertupdate.jsp page
before sumbit
After Sumbit with empty fieilds
in next post we will learn if these values are valid then insert values to database .
Labels: