Jsp Beans error
Is there any one using Sun J2EE App-Server please reply..
Also here is my query:
When I call a bean from my jsp page I get the following error .What could be the reason for it?
HTTP Status 500 -
--
type Exception report
message
description The server encountered an internal error () that prevented it from fulfillingthis request.
exception
javax.servlet.ServletException: com/stardeveloper/bean/test/MailerBean (wrong name: MailerBean)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:255)
javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:249)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:282)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:165)
root cause
java.lang.NoClassDefFoundError: com/stardeveloper/bean/test/MailerBean (wrong name: MailerBean)
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:620)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1798)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:910)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1375)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1239)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1218)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1120)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2167)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2217)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2223)
org.apache.jasper.compiler.Node$Root.accept(Node.java:460)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2167)
org.apache.jasper.compiler.Generator.generate(Generator.java:3276)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:257)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:500)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:481)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:469)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:516)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:307)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:297)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:247)
javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:249)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:282)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:165)
note The full stack trace of the root cause is available in the Sun-Java-System/Application-Server logs.
--
Sun-Java-System/Application-Server
[4093 byte] By [
rameshra] at [2007-11-26 15:49:59]

# 1
where did you put the bean class?How do you call it from the jsp page?
# 2
I put it in the classes folder inside web-inf folder
# 3
it must be on WEB-INF/classes/com/stardeveloper/bean/test/
# 4
I placed it in the same way Jhe and I compiled the jav program from my classes folder likec:\>[my working folder]\WEB-INF\classes> javac -d . com\...\MailerBean.javaStill its throwing the same error.By the way I am using Sun App Server.
# 5
where did the MailerBean.class go? i think it is in WEB-INF/classes folder and not in WEB-INF/classes/com/stardeveloper/bean/test/ forlder.. restart the server afterwards if you manage to put the class file on WEB-INF/classes/com/stardeveloper/bean/test/ forlder.. this will ensure that the class has been loaded, you don't have to start anyway
# 6
C:\Sun\AppServer\domains\domain1\applications\j2ee-modules\chk\WEB-INF\classes\com\stardeveloper\bean\test --This is where I place my MailerBean.java file andin the command prompt i went upto the above said folder and compiled the code still it throws the same error
# 7
so did the java file converted into a class file?
# 8
[nobr]The following are the codes I am trying with
inddex.html
<html>
<head>
<style>
div,input,textarea { font-family:Tahoma; font-size:8pt; }
input.std { width:200; }
div.frame { padding-left:70; }
</style>
</head>
<body>
<div class="frame">
<form action="mailer.jsp" method="post">
To :<br>
<input type="text" name="to" class="std"></input><br>
From :<br>
<input type="text" name="from" class="std"></input><br>
Subject :<br>
<input type="text" name="subject" class="std"></input><br>
Message :<br>
<textarea rows="10" cols="80" name="message"></textarea>
<br>
<input type="submit" value="Send"></input>
</form>
</div>
</body>
</html>
mailer.jsp
<%@ page errorPage="errorPage.jsp" %>
<%@ page import="com.stardeveloper.bean.test.MailerBean"%>
<html>
<head>
<style>
div,input,textarea { font-family:Tahoma; font-size:8pt; }
input.std { width:200; }
div.frame { padding-left:70; color:green; }
</style>
</head>
<body>
<div class="frame">
<jsp:useBean id="mailer" class="com.stardeveloper.bean.test.MailerBean">
<jsp:setProperty name="mailer" property="*"/>
<% mailer.sendMail(); %>
</jsp:useBean>
Email has been sent successfully.
</div>
</body>
</html>
error page.jsp
<%@ page isErrorPage="true" %>
<html>
<head>
<style>
div,input,textarea { font-family:Tahoma; font-size:8pt; }
input.std { width:200; }
div.frame { padding-left:70; color:red; }
</style>
</head>
<body>
<div class="frame">
<%= exception.getMessage() %>
</div>
</body>
</html>
MailerBean Class
package com.stardeveloper.bean.test;
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.event.*;
import javax.mail.internet.*;
public final class MailerBean extends Object implements Serializable {
/* Bean Properties */
private String to = null;
private String from = null;
private String subject = null;
private String message = null;
public static Properties props = null;
public static Session session = null;
static {
/*Setting Properties for STMP host */
props = System.getProperties();
props.put("mail.smtp.host", "mail.yourisp.com");
session = Session.getDefaultInstance(props, null);
}
/* Setter Methods */
public void setTo(String to) {
this.to = to;
}
public void setFrom(String from) {
this.from = from;
}
public void setSubject(String subject) {
this.subject = subject;
}
public void setMessage(String message) {
this.message = message;
}
/* Sends Email */
public void sendMail() throws Exception {
if(!this.everythingIsSet())
throw new Exception("Could not send email.");
try {
MimeMessage message = new MimeMessage(session);
message.setRecipient(Message.RecipientType.TO,
new InternetAddress(this.to));
message.setFrom(new InternetAddress(this.from));
message.setSubject(this.subject);
message.setText(this.message);
Transport.send(message);
} catch (MessagingException e) {
throw new Exception(e.getMessage());
}
}
/* Checks whether all properties have been set or not */
private boolean everythingIsSet() {
if((this.to == null) || (this.from == null) ||
(this.subject == null) || (this.message == null))
return false;
if((this.to.indexOf("@") == -1) ||
(this.to.indexOf(".") == -1))
return false;
if((this.from.indexOf("@") == -1) ||
(this.from.indexOf(".") == -1))
return false;
return true;
}
}
[/nobr]
# 9
the compiled class MailerBean.class must be under the C:\Sun\AppServer\domains\domain1\applications\j2ee-modules\chk\WEB-INF\classes\com\stardeveloper\bean\test directory
# 10
hai Guys,
I am new to JSP and Java Email Application. I need to send an Email from my applucation which i am struggling for a long time..I need to know whether do v want to have any changes in the SMTP Server.
While Executing the code in ths server Given below I am getting the error. Can anyoone Please help me.
1.MailerBean .java
package com.stardeveloper.bean.test;
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.event.*;
import javax.mail.internet.*;
public final class MailerBean extends Object implements Serializable {
/* Bean Properties */
private String to = null;
private String from = null;
private String subject = null;
private String message = null;
public static Properties props = null;
public static Session session = null;
static {
/*Setting Properties for STMP host */
props = System.getProperties();
props.put("mail.smtp.host", "mail.yourisp.com");
session = Session.getDefaultInstance(props, null);
}
/* Setter Methods */
public void setTo(String to) {
this.to = to;
}
public void setFrom(String from) {
this.from = from;
}
public void setSubject(String subject) {
this.subject = subject;
}
public void setMessage(String message) {
this.message = message;
}
/* Sends Email */
public void sendMail() throws Exception {
if(!this.everythingIsSet())
throw new Exception("Could not send email.");
try {
MimeMessage message = new MimeMessage(session);
message.setRecipient(Message.RecipientType.TO,
new InternetAddress(this.to));
message.setFrom(new InternetAddress(this.from));
message.setSubject(this.subject);
message.setText(this.message);
Transport.send(message);
} catch (MessagingException e) {
throw new Exception(e.getMessage());
}
}
/* Checks whether all properties have been set or not */
private boolean everythingIsSet() {
if((this.to == null) || (this.from == null) ||
(this.subject == null) || (this.message == null))
return false;
if((this.to.indexOf("@") == -1) ||
(this.to.indexOf(".") == -1))
return false;
if((this.from.indexOf("@") == -1) ||
(this.from.indexOf(".") == -1))
return false;
return true;
}
}
2.errorPage.jsp
<%@ page isErrorPage="true" %>
<html>
<head>
<style>
div,input,textarea { font-family:Tahoma; font-size:8pt; }
input.std { width:200; }
div.frame { padding-left:70; color:red; }
</style>
</head>
<body>
<div class="frame">
<%= exception.getMessage() %>
</div>
</body>
</html>
3.index.html
<html>
<head>
<style>
div,input,textarea { font-family:Tahoma; font-size:8pt; }
input.std { width:200; }
div.frame { padding-left:70; }
</style>
</head>
<body>
<div class="frame">
<form action="mailer.jsp" method="post">
To :
<input type="text" name="to" class="std"></input>
From :
<input type="text" name="from" class="std"></input>
Subject :
<input type="text" name="subject" class="std"></input>
Message :
<textarea rows="10" cols="80" name="message"></textarea>
<input type="submit" value="Send"></input>
</form>
</div>
</body>
</html>
4.mailer.jsp
<%@ page errorPage="errorPage.jsp" %>
<html>
<head>
<style>
div,input,textarea { font-family:Tahoma; font-size:8pt; }
input.std { width:200; }
div.frame { padding-left:70; color:green; }
</style>
</head>
<body>
<div class="frame">
<jsp:useBean id="mailer" class="com.stardeveloper.bean.test.MailerBean">
<jsp:setProperty name="mailer" property="*"/>
<% mailer.sendMail(); %>
</jsp:useBean>
Email has been sent successfully.
</div>
</body>
</html>
I got the Error as follows in the server
--
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 13 in the jsp file: /beta/mailer/mailer.jsp
Generated servlet error:
/web/tomcat/work/hosting/www.123lotedo.com/_/org/apache/jsp/beta/mailer/mailer_jsp.java:55: package com.stardeveloper.bean.test does not exist
com.stardeveloper.bean.test.MailerBean mailer = null;
^
An error occurred at line: 13 in the jsp file: /beta/mailer/mailer.jsp
Generated servlet error:
/web/tomcat/work/hosting/www.123lotedo.com/_/org/apache/jsp/beta/mailer/mailer_jsp.java:57: package com.stardeveloper.bean.test does not exist
mailer = (com.stardeveloper.bean.test.MailerBean) _jspx_page_context.getAttribute("mailer", PageContext.REQUEST_SCOPE);
^
2 errors
i am struggling for a long time can anybody say whats my error.
Thanks
M.S.ArunKumar
