scripter73
Programmer
Hi,
My problem is I can’t get my JSP to recognize my homemade classes. Sorry in advance for the length of this post, but need to show all info.
I’m a relative newbie to Java servlets, but here’s my 2 main class codes:
Code for User class
public class User{
private String firstName;
private String lastName;
private String emailAddress;
//constructors
public User(){}
public User(String first, String last, String email){
firstName = first;
lastName = last;
emailAddress = email;
}
//methods
public void setFirstName(String f){
firstName = f;
}
public String getFirstName(){
return firstName;
}
public void setLastName(String l){
lastName = l;
}
public String getLastName(){
return lastName;
}
public void setEmailAddress(String e){
emailAddress = e;
}
public String getEmailAddress(){
return emailAddress;
}
Code for UserIO class
import java.io.*;
public class UserIO{
public synchronized static void addRecord(User user, String filename)
throws IOException{
PrintWriter out = new PrintWriter(new FileWriter(filename,true));
out.println(user.getEmailAddress() + "|" + user.getFirstName() + "|"
+ user.getLastName());
out.close();
}
}
****************************
My Environment Setup
****************************
- Running Tomcat 4.1 with this embedded directory structure:
o \Tomcat 4.1
\webapps
\JSP
\WEB-INF
\classes User.java and UserIO.java saved here
- Running Java 2 SDK 1.4.2_02
- Environment’s System Variables:
o PATH includes c:\j2sdk1.4.2_02\bin and C:\Tomcat 4.1
o CATALINA_HOME = C:\Tomcat 4.1
o CLASSPATH = %CATALINA_HOME%\common\lib\servlet.jar;%CATALINA_HOME%\webapps\JSP\WEB-INF\classes Also tried only one of these respective directories
****************************
Error While Compiling
****************************
C:\Tomcat 4.1\webapps\JSP\WEB-INF\classes> javac User.java
C:\Tomcat 4.1\webapps\JSP\WEB-INF\classes> javac UserIO.java
Both of these compile with no problem. Now I have User.class and UserIO.class.
****************************
Run the URL.
****************************
I run which collects a first/lastname and email and then calls this .JSP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Chapter 4 - Email List Application (JSP + classes)</title>
</head>
<body>
<jsp:useBean id="user" scope="session" class="User" /> ?????? How do I import
<%
String firstname = request.getParameter("firstname");
String lastname = request.getParameter("lastname");
String emailaddress = request.getParameter("emailaddress");
User user = new User(firstName,lastName,emailAddress);
UserIO.addRecord(user,"../webapps/JSP/UserEmail.txt");
%>
<h1> Thanks for joining our email list </h1>
<p> Here is the information that you entered:</p>
<table cellspacing=5 border=0>
<tr>
<td align="right">First Name:</td>
<td><%= user.getFirstName() %></td>
</tr>
<tr>
<td align="right">Last Name:</td>
<td><%= user.getLastName() %></td>
</tr>
<tr>
<td align="right">Email Address:</td>
<td><%= user.getEmailAddress() %></td>
</tr>
</table>
<p>To enter another email address, click on the Back <br> button in your browser
or the Return button shown <br> below. </p>
<form action="join_email_list.html" method="post">
<input type="submit" value="Return">
</form>
</body>
</html>
--------
Here’s the main error message I get
Cannot resolve symbol
Symbol: class User
Then it points to my code:
User user = new User(…..)
Another error is:
Cannot resolve symbol
Symbol: variable UserIO
Then it points to my code:
UserIO.addRecord….
Among other error messages I get.
How do I import my class? I've tried the <jsp:usebean> and also tried <% page import="User,UserIO" %> to no avail. Everyone says to have your compiled classes in a \classes folder and I do.
Thanks for all of your help.
Scripter73
Change Your Thinking, Change Your Life.
My problem is I can’t get my JSP to recognize my homemade classes. Sorry in advance for the length of this post, but need to show all info.
I’m a relative newbie to Java servlets, but here’s my 2 main class codes:
Code for User class
public class User{
private String firstName;
private String lastName;
private String emailAddress;
//constructors
public User(){}
public User(String first, String last, String email){
firstName = first;
lastName = last;
emailAddress = email;
}
//methods
public void setFirstName(String f){
firstName = f;
}
public String getFirstName(){
return firstName;
}
public void setLastName(String l){
lastName = l;
}
public String getLastName(){
return lastName;
}
public void setEmailAddress(String e){
emailAddress = e;
}
public String getEmailAddress(){
return emailAddress;
}
Code for UserIO class
import java.io.*;
public class UserIO{
public synchronized static void addRecord(User user, String filename)
throws IOException{
PrintWriter out = new PrintWriter(new FileWriter(filename,true));
out.println(user.getEmailAddress() + "|" + user.getFirstName() + "|"
+ user.getLastName());
out.close();
}
}
****************************
My Environment Setup
****************************
- Running Tomcat 4.1 with this embedded directory structure:
o \Tomcat 4.1
\webapps
\JSP
\WEB-INF
\classes User.java and UserIO.java saved here
- Running Java 2 SDK 1.4.2_02
- Environment’s System Variables:
o PATH includes c:\j2sdk1.4.2_02\bin and C:\Tomcat 4.1
o CATALINA_HOME = C:\Tomcat 4.1
o CLASSPATH = %CATALINA_HOME%\common\lib\servlet.jar;%CATALINA_HOME%\webapps\JSP\WEB-INF\classes Also tried only one of these respective directories
****************************
Error While Compiling
****************************
C:\Tomcat 4.1\webapps\JSP\WEB-INF\classes> javac User.java
C:\Tomcat 4.1\webapps\JSP\WEB-INF\classes> javac UserIO.java
Both of these compile with no problem. Now I have User.class and UserIO.class.
****************************
Run the URL.
****************************
I run which collects a first/lastname and email and then calls this .JSP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Chapter 4 - Email List Application (JSP + classes)</title>
</head>
<body>
<jsp:useBean id="user" scope="session" class="User" /> ?????? How do I import
<%
String firstname = request.getParameter("firstname");
String lastname = request.getParameter("lastname");
String emailaddress = request.getParameter("emailaddress");
User user = new User(firstName,lastName,emailAddress);
UserIO.addRecord(user,"../webapps/JSP/UserEmail.txt");
%>
<h1> Thanks for joining our email list </h1>
<p> Here is the information that you entered:</p>
<table cellspacing=5 border=0>
<tr>
<td align="right">First Name:</td>
<td><%= user.getFirstName() %></td>
</tr>
<tr>
<td align="right">Last Name:</td>
<td><%= user.getLastName() %></td>
</tr>
<tr>
<td align="right">Email Address:</td>
<td><%= user.getEmailAddress() %></td>
</tr>
</table>
<p>To enter another email address, click on the Back <br> button in your browser
or the Return button shown <br> below. </p>
<form action="join_email_list.html" method="post">
<input type="submit" value="Return">
</form>
</body>
</html>
--------
Here’s the main error message I get
Cannot resolve symbol
Symbol: class User
Then it points to my code:
User user = new User(…..)
Another error is:
Cannot resolve symbol
Symbol: variable UserIO
Then it points to my code:
UserIO.addRecord….
Among other error messages I get.
How do I import my class? I've tried the <jsp:usebean> and also tried <% page import="User,UserIO" %> to no avail. Everyone says to have your compiled classes in a \classes folder and I do.
Thanks for all of your help.
Scripter73
Change Your Thinking, Change Your Life.