• Post Reply Bookmark Topic Watch Topic
  • New Topic

getting JSP to recognize my bean!!!

 
dinesh prasad
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm calling a bean to process input from a JSP. I get the following error message:
_process_jsp.java [76:1] package foo does not exist
foo.FormBean formHandler = null;
^
I'm also getting an invalid package declaration on my java bean, though it compiles.

I've placed my classes under foo/WEB-INF/classes
I tried putting the jsp in the foo directory and also WEB-Inf. I added c:\foo to my classpath. Here is my code:
process.jsp
-----------
<%@ page import="java.util.*" %>
<%!
ResourceBundle bundle =null;
public void jspInit() {
bundle = ResourceBundle.getBundle("forms");
}
%>
<jsp:useBean id="formHandler" class="foo.FormBean" scope="request">
<jsp:setProperty name="formHandler" property="*"/>
</jsp:useBean>
<% if (formHandler.validate()) {
%>
<%--
<jsp:forward page="<%=bundle.getString(\"process.success\")%>"/>
--%>
<jsp:forward page="/DBHandler"/>
<%
} else {
%>
<jsp:forward page="<%=bundle.getString(\"process.retry\")%>"/>
<%
}
%>
____________________________________________
FormBean.class
package foo;
import java.util.*;
public class FormBean {

private String email;
private String userName;
private String password1;
private String password2;
private String displayname;
private Hashtable errors;

public boolean validate() {
boolean allOk=true;

if (email.equals("") || (email.indexOf('@') == -1)) {
errors.put("email","Please enter a valid email address");
email="";
allOk=false;
}
if (userName.equals("")) {
errors.put("userName","Please enter a username");
userName="";
allOk=false;
}
if (password1.equals("")) {
errors.put("password1","Please enter a valid password");
password1="";
allOk=false;
}
if (!password1.equals("") && (password2.equals("") || !password1.equals(password2))) {
errors.put("password2","Please confirm your password");
password2="";
allOk=false;
}
if (displayname.equals("") ) {
errors.put("displayname", "Please enter a display name");
displayname="";
allOk=false;
}


return allOk;
}

public FormBean() {

email="";
password1="";
password2="";
displayname="";

errors = new Hashtable();
}

public String getEmail() {
return email;
}

public String getPassword1() {
return password1;
}

public String getPassword2() {
return password2;
}
public String displayname() {
return displayname;
}


public void setEmail(String eml) {
email=eml;
}

public void setPassword1(String p1) {
password1=p1;
}
public void setPassword2(String p2) {
password2=p2;
}
public void setdisplayname(String dp) {
displayname=dp;
}


}
Thanks for any help!!
Dinesh
[ June 26, 2003: Message edited by: dinesh prasad ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to import foo.* or foo.FormBean in a <%@page directive - just defining it in a useBean is not enough.
Bill
 
dinesh prasad
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that seems to have worked. Now, I'm getting another error message about the package.

An error occurred at line: 10 in the JSP file: /process.jsp
Generated servlet error:
Class _jasper.FormBean not found.
FormBean formHandler = null;
^
Here is the directory structure:
examples2/ <- jsp/html files
examples2/WEB-INF <- web.xml
examples2/WEB-INF/classes/foo <- FormBean.class
I'm using the sun one studio developer, it has a bundled application server.
Any more suggestions?
[ June 27, 2003: Message edited by: dinesh prasad ]
 
Nick Ueda
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow...this is great I might actually be of some help...
Looks like you may be having the same as I had earlier this week. Make sure your context path is set up properly.
Look in the manual or the docs of the bundled
server on information on how to do this (if this is the problem)
I hope I have diagnosed the problem properly and good luck on fixing it...
It may look something like this...
<Context path="/example2"
docBase="d:/baseinstalldirectory/pathstuff/examples2"
debug="0"
reloadable="true"
crossContext="true"/>
but I cannot gaurantee that is exactly what it will look like...
-Nick Ueda
[ June 28, 2003: Message edited by: Nick Ueda ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!