• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help? Compliation Errors  RSS feed

 
marc stein
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having problems trying to compile this .java file. The name of the file is EmployeeListAction.java

package com.fprb;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.ArrayList;
public class EmployeeListAction extends Action {
protected ArrayList getEmployees() {
Employee employee = null;
ArrayList employees = new ArrayList();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
ServletContext context = servlet.getServletContext();
DataSource dataSource = (DataSource)
context.getAttribute(Action.DATA_SOURCE_KEY);
try {
conn = dataSource.getConnection();
stmt = conn.createStatement();
rs =
stmt.executeQuery("select * from employees, roles, "
+ "departments where employees.roleid=roles.roleid "
+ "and employees.depid=departments.depid");
while ( rs.next() ) {
employee = new Employee();
employee.setUsername(rs.getString("username"));
employee.setName(rs.getString("name"));
employee.setRolename(rs.getString("rolename"));
employee.setPhone(rs.getString("phone"));
employee.setEmail(rs.getString("email"));
employee.setRoleid(new Integer(rs.getInt("roleid")));
employee.setDepid(new Integer(rs.getInt("depid")));
employee.setDepartment(rs.getString("depname"));
employees.add(employee);
System.err.println("Username : "
+ employee.getUsername()
+ " Department : " + rs.getString("depname"));
}
}
catch (SQLException e) {
System.err.println(e.getMessage());
}
finally {
if (rs != null) {
try {
rs.close();
}
catch (SQLException sqle) {
System.err.println(sqle.getMessage());
}
rs = null;
}
if (stmt != null) {
try {
stmt.close();
}
catch (SQLException sqle) {
System.err.println(sqle.getMessage());
}
stmt = null;
}
if (conn != null) {
try {
conn.close();
}
catch (SQLException sqle) {
System.err.println(sqle.getMessage());
}
conn = null;
}
}
return employees;
}
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
// Default target to success
String target = new String("success");
EmployeesActionMapping employeesMapping =
(EmployeesActionMapping)mapping;
// Does this action require the user to login
if ( employeesMapping.isLoginRequired() ) {
HttpSession session = request.getSession();
if ( session.getAttribute("USER") == null ) {
// The user is not logged in
target = new String("login");
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("errors.login.required"));
// Report any errors we have discovered back to
// the original form
if (!errors.empty()) {
saveErrors(request, errors);
}
}
}
ArrayList employees = null;
employees = getEmployees();
// Set the target to failure
if ( employees == null ) {
target = new String("login");
}
else {
request.setAttribute("employees", employees);
}
// Forward to the appropriate View
return (mapping.findForward(target));
}
}
When I compile the code here is what happens, notice j2sdk1.4 is being used here and the Struts framework:

C:\j2sdk1.4>cd bin
C:\j2sdk1.4\bin>javac C:\tomcat4\webapps\fprbdb\WEB-INF\classes\EmployeeListActi
on.java
C:\tomcat4\webapps\fprbdb\WEB-INF\classes\EmployeeListAction.java:28: cannot res
olve symbol
symbol : class Employee
location: class com.fprb.EmployeeListAction
Employee employee = null;
^
C:\tomcat4\webapps\fprbdb\WEB-INF\classes\EmployeeListAction.java:49: cannot res
olve symbol
symbol : class Employee
location: class com.fprb.EmployeeListAction
employee = new Employee();
^
C:\tomcat4\webapps\fprbdb\WEB-INF\classes\EmployeeListAction.java:122: cannot re
solve symbol
symbol : class EmployeesActionMapping
location: class com.fprb.EmployeeListAction
EmployeesActionMapping employeesMapping =
^
C:\tomcat4\webapps\fprbdb\WEB-INF\classes\EmployeeListAction.java:123: cannot re
solve symbol
symbol : class EmployeesActionMapping
location: class com.fprb.EmployeeListAction
(EmployeesActionMapping)mapping;
^
4 errors
any ideas on what is wrong with this code? I am new to the java programming language and could use some help troubleshooting. Thanks
Marc
 
Tom Purl
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your program can't find the Employee or EmployeesActionMapping classes in the packages that you imported. I checked the 1.4 api and the struts api and I couldn't find them either. Did you forget to import something?
 
marc stein
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The two classes are present in the com.fprb folder. Here they are. Any other suggestions? Thanks. Marc
package com.fprb;
public class Employee {
protected String username;
protected String name;
protected String department;
protected String rolename;
protected String phone;
protected String email;
protected Integer depid;
protected Integer roleid;
public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setDepartment(String department) {
this.department = department;
}
public String getDepartment() {
return this.department;
}
public void setRolename(String rolename) {
this.rolename = rolename;
}
public String getRolename() {
return rolename;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getPhone() {
return phone;
}
public void setEmail(String email) {
this.email = email;
}
public String getEmail() {
return email;
}
public void setDepid(Integer depid) {
this.depid = depid;
}
public Integer getDepid() {
return depid;
}
public void setRoleid(Integer roleid) {
this.roleid = roleid;
}
public Integer getRoleid() {
return roleid;
}
}
package com.fprb;
import org.apache.struts.action.ActionMapping;
public class EmployeesActionMapping extends ActionMapping {
protected boolean loginRequired = false;
public EmployeesActionMapping() {
super();
}
public void setLoginRequired(boolean loginRequired) {
this.loginRequired = loginRequired;
}
public boolean isLoginRequired() {
return loginRequired;
}
}
 
Tom Purl
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that your EmployeeListAction.java file should be in the same folder as your Employee.java and EmployeesActionMapping.java files. For files to be in the same package they have to be in the same folder.
 
marc stein
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all! The classpath had to be set properly for the FPRBDB application. I complied with no errors. This site Rocks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!