Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

It just won't compile

Status
Not open for further replies.

TyzA

Programmer
Jan 7, 2002
86
BE
Hi,

I keep on getting this error and don't know what to do with it. I have one servlet (see code below) which creates a MailServlet object and calls the MailServlet to send the mail. I have placed the mail.jar and activation.jar in the lib dir of my web-application.
Hope you can help:

ERROR MSG:
----------
About.java:164: cannot access com.comparitel.web.util.MailServlet
bad class file: C:\Program Files\Apache Group\Tomcat 4.1\webapps\comparitel\WEB-
INF\classes\com\comparitel\web\util\MailServlet.java
file does not contain class com.comparitel.web.util.MailServlet
Please remove or make sure it appears in the correct subdirectory of the classpath.
MailServlet mail = new MailServlet();
^
1 error



CODE ABOUT.JAVA:
----------------
package com.comparitel.web.general;

//=============================== Imports ============================
import java.io.*;
import java.sql.*;

import javax.servlet.*;
import javax.servlet.http.*;

import com.comparitel.util.*;
import com.comparitel.core.*;
import com.comparitel.db.*;
import com.comparitel.appint.*;

import com.comparitel.web.util.*;

import com.javaexchange.dbConnectionBroker.*;

public class About extends HttpServlet{

//============================ Declarations =======================
public String strTittle="", strMailTo="", strParam="";

//=========================== Public Methods ======================

/*-----------------------------------------------------------------
* Method: doGet
* Description: This method will catch all incomming requests from the GUI
*-----------------------------------------------------------------*/
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

String strMethod = "About.doGet";
StringBuffer strHtml = new StringBuffer();

// get DB connection and log object
DbConnectionBroker pool = (DbConnectionBroker) getServletContext().getAttribute(Global.CONTEXT_CONN_POOL);
Log log = (Log) getServletContext().getAttribute(Global.CONTEXT_LOG);

Connection conn = null;

PrintWriter out = res.getWriter();

String strMailTo = req.getParameter("emailTo");

boolean b = getDetails(strMailTo);

if ( b )
{
res.setContentType("text/html");

conn = pool.getConnection();

if ( conn!=null )
{
strHtml.append(&quot;<html>\n&quot;);
strHtml.append(&quot;<head>\n&quot;);
strHtml.append(&quot;<title>\n&quot;);

strHtml.append(strTittle);

strHtml.append(&quot;</title>\n&quot;);
strHtml.append(&quot;<link rel=\&quot;stylesheet\&quot; type=\&quot;text/css\&quot; href=\&quot;css-lib/Comparitel_All.css\&quot;>\n&quot;);
strHtml.append(&quot;<SCRIPT LANGUAGE=\&quot;JavaScript\&quot; SRC=\&quot;scripts/ValidateCustomerForm.js\&quot;></SCRIPT>\n&quot;);
strHtml.append(&quot;</head>\n&quot;);
strHtml.append(&quot;<body leftmargin=\&quot;0\&quot; topmargin=\&quot;0\&quot; marginwidth=\&quot;0\&quot; marginheight=\&quot;0\&quot;>\n&quot;);
strHtml.append(&quot;<table width=\&quot;750\&quot; cellspacing=\&quot;0\&quot; cellpadding=\&quot;0\&quot; border=\&quot;0\&quot; leftmargin=\&quot;0\&quot; topmargin=\&quot;0\&quot; marginwidth=\&quot;0\&quot; marginheight=\&quot;0\&quot;>\n&quot;);
strHtml.append(&quot;<tr><td colspan=\&quot;3\&quot; align=\&quot;center\&quot;>\n&quot;);
strHtml.append(&quot;<img src=\&quot;images/general/spacer.gif\&quot; alt=\&quot;\&quot; width=\&quot;1\&quot; height=\&quot;40\&quot; border=\&quot;0\&quot;>\n&quot;);
strHtml.append(&quot;</td></tr><tr>\n&quot;);
strHtml.append(&quot;<td rowspan=\&quot;2\&quot;>\n&quot;);
strHtml.append(&quot;<img src=\&quot;images/general/spacer.gif\&quot; alt=\&quot;\&quot; width=\&quot;10\&quot; height=\&quot;1\&quot; border=\&quot;0\&quot;>\n&quot;);
strHtml.append(&quot;</td>\n&quot;);
strHtml.append(&quot;<td class=\&quot;green\&quot; colspan=\&quot;2\&quot;>\n&quot;);
strHtml.append(&quot;<strong>\n&quot;);

strHtml.append(strTittle);

strHtml.append(&quot;</strong>\n&quot;);
strHtml.append(&quot;<br><br>\n&quot;);
strHtml.append(&quot;Tell us what you think &quot;);

strHtml.append(strTittle);

strHtml.append(&quot;<br><br>\n&quot;);
strHtml.append(&quot;You can fill in the form or contact us directly at: <a class=\&quot;green\&quot; tabindex=\&quot;1\&quot; href=\&quot;mailto:&quot;);
strHtml.append(strMailTo);
strHtml.append(&quot;\&quot;>&quot;);

strHtml.append(strMailTo);

strHtml.append(&quot;</a>\n&quot;);
strHtml.append(&quot;<br><br> </td></tr><tr>\n&quot;);
strHtml.append(&quot;<td class=\&quot;green\&quot; >\n&quot;);
strHtml.append(&quot;<form method=\&quot;POST\&quot; name=\&quot;ctForm\&quot; onSubmit=\&quot;return ValidateForm('contact')\&quot; action=\&quot;sentmail\&quot;>\n&quot;);
strHtml.append(&quot;Email address: <br>\n&quot;);
strHtml.append(&quot;<input class=\&quot;contact\&quot; type=\&quot;text\&quot; name=\&quot;email\&quot; size=\&quot;65\&quot; tabindex=\&quot;2\&quot;><br>\n&quot;);
strHtml.append(&quot;<br>\n&quot;);
strHtml.append(&quot;Comment: <br>\n&quot;);
strHtml.append(&quot;<textarea class=\&quot;contact\&quot; cols=\&quot;67\&quot; rows=\&quot;10\&quot; name=\&quot;message\&quot;></textarea><br>\n&quot;);
strHtml.append(&quot;<input class=\&quot;greenBtn\&quot; type=\&quot;submit\&quot; name=\&quot;send\&quot; value=\&quot;Send\&quot;>\n&quot;);

strHtml.append(&quot;<input class=\&quot;greenBtn\&quot; type=\&quot;hidden\&quot; name=\&quot;mailTo\&quot; value=\&quot;&quot;);
strHtml.append(strParam);
strHtml.append(&quot;\&quot;>\n&quot;);

strHtml.append(&quot;</td>\n&quot;);
strHtml.append(&quot;<td class=\&quot;green\&quot; width=\&quot;150\&quot;> \n&quot;);
strHtml.append(&quot;</td></tr></table></form></body></html>\n&quot;);

pool.freeConnection(conn);
out.println(strHtml.toString());
}
else
{
System.out.println(&quot;No Connection object - &quot;+strMethod);
log.out(strMethod,Global.LOG_ERR,&quot;no connection&quot;,conn);
}
}
else
{
System.out.println(&quot;Error while setting the parameters&quot;);
log.out(strMethod,Global.LOG_ERR,&quot;Error while setting the parameters&quot;,conn);
}// end boolean check
} // end doget

public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

ServletContext context = getServletContext();

String strHost = (String)context.getAttribute(Global.MAIL_HOST);
String strUsr = (String)context.getAttribute(Global.MAIL_USR);
String strPwd = (String)context.getAttribute(Global.MAIL_PWD);
String strSMTP = (String)context.getAttribute(Global.MAIL_SMTP);

PrintWriter out = res.getWriter();
String strMethod = &quot;About.doPost&quot;;
StringBuffer strHtml = new StringBuffer();

String strMailFrom = req.getParameter(&quot;email&quot;);
String strMsg = req.getParameter(&quot;message&quot;);
String strParm = req.getParameter(&quot;mailTo&quot;);

boolean b = getDetails(strParm);

MailServlet mail = new MailServlet();

mail.mailFrom = strMailFrom;
mail.host = strHost;
mail.sendHost = strSMTP;
mail.mailUser = strUsr;
mail.mailPwd = strPwd;
mail.mailTo = strMailTo;

boolean a = mail.sendMail(strTittle,strMsg);

strHtml.append(&quot;<html>\n&quot;);
strHtml.append(&quot;<head>\n&quot;);
strHtml.append(&quot;<title>[tittle from the global file]</title>\n&quot;);
strHtml.append(&quot;<link rel=\&quot;stylesheet\&quot; type=\&quot;text/css\&quot; href=\&quot;css-lib/Comparitel_All.css\&quot;>\n&quot;);
strHtml.append(&quot;</head>\n&quot;);
strHtml.append(&quot;<body leftmargin=\&quot;0\&quot; topmargin=\&quot;0\&quot; marginwidth=\&quot;0\&quot; marginheight=\&quot;0\&quot;>\n&quot;);
strHtml.append(&quot;<table width=\&quot;750\&quot; cellspacing=\&quot;0\&quot; cellpadding=\&quot;0\&quot; border=\&quot;0\&quot; leftmargin=\&quot;0\&quot; topmargin=\&quot;0\&quot; marginwidth=\&quot;0\&quot; marginheight=\&quot;0\&quot;>\n&quot;);
strHtml.append(&quot;<tr><td colspan=\&quot;3\&quot; align=\&quot;center\&quot;>\n&quot;);
strHtml.append(&quot;<h1>Thanks for you comment<h1>\n&quot;);
strHtml.append(&quot;</td></tr></table></form></body></html>\n&quot;);

out.println(strHtml.toString());

} // end doPost

public boolean getDetails(String strMailTo)
{
if ( strMailTo!=null && strMailTo.equals(Global.ABOUT_US) )
{
strTittle=Global.CONTACT_TITTLE_AU;
strMailTo=Global.MAIL_ADDR_INFO;
strParam=Global.ABOUT_US;
}
else
return false;

if ( strMailTo!=null && strMailTo.equals(Global.ABOUT_BC) )
{
strTittle=Global.CONTACT_TITTLE_BC;
strMailTo=Global.MAIL_ADDR_BC;
strParam=Global.ABOUT_BC;
}
else
return false;

if ( strMailTo!=null && strMailTo.equals(Global.ABOUT_BA) )
{
strTittle=Global.CONTACT_TITTLE_BA;
strMailTo=Global.MAIL_ADDR_BA;
strParam=Global.ABOUT_BA;
}
else
return false;

if ( strMailTo!=null && strMailTo.equals(Global.ABOUT_CS) )
{
strTittle=Global.CONTACT_TITTLE_CS;
strMailTo=Global.MAIL_ADDR_CS;
strParam=Global.ABOUT_CS;
}
else
return false;

return true;

} // end getDetails

} // end class
 
I did some experimenting and found that Tomcat will give that error if a class is in a directory structure that does not match the package structure.

Probably MailServlet is missing or has an incorrect &quot;package&quot; declaration at the top.
 
Thanks,

I just forgot that one
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top