Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP Error Page Not Comiling  RSS feed

 
wasif akbar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created an error page that captures any exceptions thrown from the container and sends an email to me. Unfortunately, it doesn't want to cooperate and won't compile. I have attached the code from the JSP Error page as well as the error message the is sent to my browser. Thanks for your help.
JSP PAGE:
<HTML>
<HEAD>
<%@ page isErrorPage="true" %>
<% System.out.println("1"); %>
<%@ page import="java.util.*" %>
<% System.out.println("2"); %>
<%@ page import="java.io.*" %>
<% System.out.println("3"); %>
<%@ page import="javax.mail.*" %>
<% System.out.println("4"); %>
<%@ page import="javax.mail.internet.*" %>
<% System.out.println("5"); %>
<TITLE>Error Page</TITLE>
</HEAD>
<BODY>
<H1>An error has occurred:</H1><BR>
<center><b><% =exception %></b></center>
<% try {
String mailServer = "smtp.ffx.teoco.com";
String subject = "Technical Support Website Error Message";
String [] to = {"akbarw@teoco.com"};
String from = "akbarw@teoco.com";
sendEmail(mailServer, subject, to, from, makeErrorReport(request, exception));
%>
<P>Please contact <a href="customer.service@teoco.com"> TEOCO's Technical Support</a></P>
<% }
catch(AddressException e)
{
%>
<P>Invalid email address for error notification.</P>
<% }
catch(MessagingException me)
{
%>
<P>Unable to send email for error notification.</P>
<% }
%>
</BODY>
</HTML>
<%!
public String makeErrorReport(HttpServletRequest req, Throwable e)
{
StringBuffer buffer = new StringBuffer();
reportException(buffer, e);
reportRequest(buffer, req);
reportParameters(buffer, req);
return buffer.toString();
}
public void reportException(StringBuffer buffer, Throwable e)
{
StringWriter writer = new StringWriter();
e.printStackTrace(new PrintWriter(writer));
buffer.append(writer.getBuffer());
buffer.append("\n");
}
public void reportRequest(StringBuffer buffer, HttpServletRequest req)
{
buffer.append("Request: ");
buffer.append(req.getMethod());
buffer.append(" ");
buffer.append(HttpUtils.getRequestURL(req));
String queryString = req.getQueryString();
if(queryString != null)
{
buffer.append("?");
buffer.append(queryString);
}
buffer.append("\nSession ID: ");
Session sessionId = req.getRequestedSessionId();
if(sessionId == null)
{
buffer.append("none");
}
else if(req.isRequestedSessionIdValid())
{
buffer.append(sessionId);
}
}
public void reportParameters(StringBuffer buffer, HttpServletRequest req)
{
Enumeration names = req.getParameterNames();
if(names.hasMoreElements())
{
buffer.append("Parameters: \n");
while(names.hasMoreElements())
{
String name = (String)names.nextElement();
String [] values = req.getParameterValues(name);
for(int i=0; i<values.length(); ++i)
{
buffer.append(" ");
buffer.append(name);
buffer.append(" = ");
buffer.append(values[i]);
buffer.append("\n");
}
}
}
}
public String sendEmail(String mailServer, String subject, String to[],
String from, String messageText)
throws AddressException, MessagingException
{
//Create Session
Properties mailProps = new Properties();
mailProps.put("mail.smtp.host", mailServer);
Session mailSession = Session.getDefaultInstance(mailProps, null);
//Construct addresses
int toCount = to.length;
InternetAddress[] toAddrs = new InternetAddress[toCount];
for(int i=0; i<toCount; ++i)
{
toAddrs[i] = new InternetAddress(to[i]);
}
InternetAddress fromAddr = new InternetAddress(from);
//Create and initialize message
Message message = new MimeMessage(mailSession);
message.setFrom(fromAddr);
message.setRecipients(Message.RecipientType.TO, toAddrs);
message.setSubject(subject);
message.setContent(messageText.toString(), "text/plain");
//Send message
Transport.send(message);
}
%>

ERROR IN BROWSER:

A Servlet Exception Has Occurred
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occured between lines: 12 and 17 in the jsp file: /error.jsp
Generated servlet error:
C:\jakarta-tomcat-4.0\work\localhost\technical_support\error$jsp.java:205: Missing term.
out.write("\r\n\r\n\r\n\r\nAn error has occurred:\r\n");
^
1 error
at org.apache.jasper.compiler.Compiler.compile(Unknown Source)
at org.apache.jasper.servlet.JspServlet.loadJSP(Unknown Source)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(Unknown Source)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(Unknown Source)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(Unknown Source)
at org.apache.jasper.servlet.JspServlet.service(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationDispatcher.invoke(Unknown Source)
at org.apache.catalina.core.ApplicationDispatcher.doForward(Unknown Source)
at org.apache.catalina.core.ApplicationDispatcher.forward(Unknown Source)
at com.teoco.tsweb.admin.AdministrationServlet.doPost(AdministrationServlet.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source)
at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardContext.invoke(Unknown Source)
at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.valves.AccessLogValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invokeNext(Unknown Source)
at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
at org.apache.catalina.connector.http.HttpProcessor.process(Unknown Source)
at org.apache.catalina.connector.http.HttpProcessor.run(Unknown Source)
at java.lang.Thread.run(Thread.java:484)
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe your mixing of page directives with scriptlets has confused it. Try creating a single page directive at the very start of the JSP.
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!