Skip to Main Content

errorMap put variable in a jsp results in a "cannot be resolved to a type"

934290May 1 2012 — edited May 10 2012
My first try at jsp programming...

I am trying to run the following jsp and running into the error as

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 49 in the jsp file: /docbase_admin/useradmin/example.jsp
User1.ERR_EMAIL_ENTER cannot be resolved to a type
46: // Define error messages
47: java.util.Map errorMap = new java.util.HashMap();
48: public void jspInit() {
49: errorMap.put(User1.ERR_EMAIL_ENTER, "Please enter an email address");
50: errorMap.put(User1.ERR_EMAIL_INVALID, "The email address is not valid");
51: errorMap.put(User1.ERR_ZIPCODE_ENTER, "Please enter a zipcode");
52: errorMap.put(User1.ERR_ZIPCODE_INVALID, "The zipcode must be 5 digits");

The original jsp is as follows

<%-- Instantiate the form validation bean and supply the error message map --%>
<%@ page import="com.test.*" %>
<jsp:useBean id="User1" class="com.test.ops.admin.User1" scope="request">
<jsp:setProperty name="User1" property="errorMessages" value='<%= errorMap %>'/>
</jsp:useBean>

<%
// If process is true, attempt to validate and process the form
if ("true".equals(request.getParameter("process"))) {
%>
<jsp:setProperty name="form" property="*" />
<%
// Attempt to process the form
if (form.process()) {
// Go to success page
response.sendRedirect("formDone.jsp");
return;
}
}
%>

<html>
<head><title>A Simple Form</title></head>
<body>

<%-- When submitting the form, resubmit to this page --%>
<form action='<%= request.getRequestURI() %>' method="POST">
<%-- email --%>
<font color=red><%= form.getErrorMessage("email") %></font><br>
Email: <input type="TEXT" name="email" value='<%= form.getEmail() %>'>
<br>

<%-- zipcode --%>
<font color=red><%= form.getErrorMessage("zipcode") %></font><br>
Zipcode: <input type="TEXT" name="zipcode" value='<%= form.getZipcode() %>'>
<br>

<input type="SUBMIT" value="OK">
<input type="HIDDEN" name="process" value="true">
</form>

</body>
</html>

<%!
// Define error messages
java.util.Map errorMap = new java.util.HashMap();
public void jspInit() {
errorMap.put(User1.ERR_EMAIL_ENTER, "Please enter an email address");
errorMap.put(User1.ERR_EMAIL_INVALID, "The email address is not valid");
errorMap.put(User1.ERR_ZIPCODE_ENTER, "Please enter a zipcode");
errorMap.put(User1.ERR_ZIPCODE_INVALID, "The zipcode must be 5 digits");
errorMap.put(User1.ERR_ZIPCODE_NUM_ONLY, "The zipcode must contain only digits");
}
%>

The User1.class is correctly available under WEB-INF/classes/com/test/ops/admin/ folder

Any help/guidance is greatly appreciated
Comments
Post Details
Added on May 1 2012
1 comment
614 views