New here to JSP/Servlets and am trying to work through the Murach's
Java Servlets and
JSP book. I am stuck however. I keep getting a HTTP Status 500 - Unable to compile class for JSP.
I am using Eclipse Kepler, JDK 1.7, and
Tomcat v7.0 server.
Its a fairly simple program that takes in user information, first name, last name, and an email and processes the information, saving the data to a text file.
------------------------------------------------
I have two Java classes: User and UserIO
-------------------------------------------------
//User.java
-------------------------
//UserIO.java
package data;
import java.io.*;
import business.User;
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();
}
}
------------------------------------------------------------------------------------------
I also have an html page to collect user information: join_email_list.html
--------------------------------------------------------------------------------------------
<!DOCTYPE html>
<html>
<head>
<title>Chapter 4 - Email List application</title>
</head>
<body>
<h1>Join our email list</h1>
<p>To join our email list, enter yourname and email address below <br>
Then, click on the submit button.
</p>
<form action="show_email_entry.jsp" method="get">
<table>
<tr>
<td align="right">First name:</td>
<td><input type="text" name="firstName"/></td>
</tr>
<tr>
<td align="right">Last name:</td>
<td><input type="text" name="lastName"/></td>
</tr>
<tr>
<td align="right">Email address:</td>
<td><input type="text" name="emailAddress"/></td>
</tr>
<tr>
<td></td>
<td><br><input type="submit" value="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>
--------------------------------------------------------------------------------
...and the JSP page to process it: show_email_entry.jsp
------------------------------------------------------------------------------
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Chapter 4 - Email List application</title>
</head>
<body>
<%@ page import="business.User, data.UserIO, java.util.Date" %>
<%! int accessCount = 0; %>
<%! String filename ="../WEB-INF/UserEmail.txt"; %>
<%
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, filename);
int localCount = 0;
synchronized(this){
accessCount++;
localCount = accessCount;
}
%>
<%
for(int x = 0; x < 5; x++){
%>
<p> Welcome <%= firstName %> <%= lastName %> </p>
<%
}
%>
<h1> Thanks for joining our email list </h1>
<p>We are excited to have you!</p>
<p>Here is the information that you entered</p>
<table cellspacing="5" cellpadding="5" border="1">
<tr>
<td align="right">First name:</td>
<td><%= firstName %></td>
</tr>
<tr>
<td align="right">Last name:</td>
<td><%= lastName %></td>
</tr>
<tr>
<td align="right">Email address:</td>
<td><%= emailAddress %></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>
Today's date is <%= new Date() %>. <br>
<em>This page has been accessed <%= localCount %> times.</em>
</body>
</html>
-------------------------------------------------------------------
However after trying to run it it get the following errors:
-------------------------------------------------------------------
Jul 05, 2014 10:57:29 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.7.0_11\jre\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Java\jdk1.7.0_06\bin;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Ruby193\bin;C:\Program Files (x86)\Java\jdk1.7.0_06\bin;C:\Program Files (x86)\Heroku\bin;C:\Program Files (x86)\git\cmd;C:\Program Files\TortoiseHg\;C:\Program Files\Java\jdk1.7.0_11\bin;C:\Program Files\Apache Software Foundation\apache-maven-3.2.1\bin;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\play;.
Jul 05, 2014 10:57:29 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:SimpleServletProject' did not find a matching property.
Jul 05, 2014 10:57:29 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:ServletProject' did not find a matching property.
Jul 05, 2014 10:57:29 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Email_Project' did not find a matching property.
Jul 05, 2014 10:57:29 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jul 05, 2014 10:57:29 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jul 05, 2014 10:57:29 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 432 ms
Jul 05, 2014 10:57:29 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jul 05, 2014 10:57:29 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.54
Jul 05, 2014 10:57:30 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files (x86)\Tomcat_7.0.54\webapps\docs
Jul 05, 2014 10:57:30 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\Program Files (x86)\Tomcat_7.0.54\webapps\docs has finished in 51 ms
Jul 05, 2014 10:57:30 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files (x86)\Tomcat_7.0.54\webapps\examples
Jul 05, 2014 10:57:30 AM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Jul 05, 2014 10:57:30 AM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Jul 05, 2014 10:57:30 AM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache@22536cc0')
Jul 05, 2014 10:57:30 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\Program Files (x86)\Tomcat_7.0.54\webapps\examples has finished in 322 ms
Jul 05, 2014 10:57:30 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files (x86)\Tomcat_7.0.54\webapps\host-manager
Jul 05, 2014 10:57:30 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\Program Files (x86)\Tomcat_7.0.54\webapps\host-manager has finished in 53 ms
Jul 05, 2014 10:57:30 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files (x86)\Tomcat_7.0.54\webapps\manager
Jul 05, 2014 10:57:30 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\Program Files (x86)\Tomcat_7.0.54\webapps\manager has finished in 45 ms
Jul 05, 2014 10:57:30 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Program Files (x86)\Tomcat_7.0.54\webapps\ROOT
Jul 05, 2014 10:57:30 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\Program Files (x86)\Tomcat_7.0.54\webapps\ROOT has finished in 37 ms
Jul 05, 2014 10:57:30 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jul 05, 2014 10:57:30 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jul 05, 2014 10:57:30 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 999 ms
Jul 05, 2014 10:57:39 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/Email_Project] threw exception [Unable to compile class for JSP:
An error occurred at line: [14] in the generated java file: [C:\Program Files (x86)\Tomcat_7.0.54\work\Catalina\localhost\Email_Project\org\apache\jsp\show_005femail_005fentry_jsp.java]
Only a type can be imported. business.User resolves to a package
An error occurred at line: [15] in the generated java file: [C:\Program Files (x86)\Tomcat_7.0.54\work\Catalina\localhost\Email_Project\org\apache\jsp\show_005femail_005fentry_jsp.java]
Only a type can be imported. data.UserIO resolves to a package
An error occurred at line: 18 in the jsp file: /show_email_entry.jsp
User cannot be resolved to a type
15: String lastName = request.getParameter("lastName");
16: String emailAddress = request.getParameter("emailAddress");
17:
18: User user = new User(firstName, lastName, emailAddress);
19: UserIO.addRecord(user, filename);
20: int localCount = 0;
21: synchronized(this){
An error occurred at line: 18 in the jsp file: /show_email_entry.jsp
User cannot be resolved to a type
15: String lastName = request.getParameter("lastName");
16: String emailAddress = request.getParameter("emailAddress");
17:
18: User user = new User(firstName, lastName, emailAddress);
19: UserIO.addRecord(user, filename);
20: int localCount = 0;
21: synchronized(this){
An error occurred at line: 19 in the jsp file: /show_email_entry.jsp
UserIO cannot be resolved
16: String emailAddress = request.getParameter("emailAddress");
17:
18: User user = new User(firstName, lastName, emailAddress);
19: UserIO.addRecord(user, filename);
20: int localCount = 0;
21: synchronized(this){
22: accessCount++;
Stacktrace:] with root cause
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: [14] in the generated java file: [C:\Program Files (x86)\Tomcat_7.0.54\work\Catalina\localhost\Email_Project\org\apache\jsp\show_005femail_005fentry_jsp.java]
Only a type can be imported. business.User resolves to a package
An error occurred at line: [15] in the generated java file: [C:\Program Files (x86)\Tomcat_7.0.54\work\Catalina\localhost\Email_Project\org\apache\jsp\show_005femail_005fentry_jsp.java]
Only a type can be imported. data.UserIO resolves to a package
An error occurred at line: 18 in the jsp file: /show_email_entry.jsp
User cannot be resolved to a type
15: String lastName = request.getParameter("lastName");
16: String emailAddress = request.getParameter("emailAddress");
17:
18: User user = new User(firstName, lastName, emailAddress);
19: UserIO.addRecord(user, filename);
20: int localCount = 0;
21: synchronized(this){
An error occurred at line: 18 in the jsp file: /show_email_entry.jsp
User cannot be resolved to a type
15: String lastName = request.getParameter("lastName");
16: String emailAddress = request.getParameter("emailAddress");
17:
18: User user = new User(firstName, lastName, emailAddress);
19: UserIO.addRecord(user, filename);
20: int localCount = 0;
21: synchronized(this){
An error occurred at line: 19 in the jsp file: /show_email_entry.jsp
UserIO cannot be resolved
16: String emailAddress = request.getParameter("emailAddress");
17:
18: User user = new User(firstName, lastName, emailAddress);
19: UserIO.addRecord(user, filename);
20: int localCount = 0;
21: synchronized(this){
22: accessCount++;
Stacktrace:
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:476)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:657)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:722)
-----------------------------------------------------------------------------
I have the following structure in my program: See attached picture
-----------------------------------------------------------------------------
Any help will be appreciated.