File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes SimpleEmail through JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "SimpleEmail through JSP" Watch "SimpleEmail through JSP" New topic
Author

SimpleEmail through JSP

Rajesh Balu
Ranch Hand

Joined: Nov 07, 2011
Posts: 55
Hi,


I am trying to send e-mails through JSP page. I just got the below code.

<%
SimpleEmail email = new SimpleEmail();
email.setHostName("hostname");
email.addTo("TO", "Balu, Rajesh");
email.setFrom("FROM", "Balu, Rajesh");
email.setSubject("Test message");
email.setMsg("This is a simple test of commons-email");
email.send();
%>


It is working fine in stand-alone java program. But i am getting the below error if i try the same code in JSP page.

D:\Srvapps\was70-ws01\profiles\was70-ws01-01\temp\node70-ws01-01\jvm70-ws01-01\TravelRequestEAR\RC_PRISM_Travel.war\_TestPage.java : 94 : SimpleEmail cannot be resolved to a type

at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.translateJsp(AbstractJSPExtensionServletWrapper.java:468)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper._checkForTranslation(AbstractJSPExtensionServletWrapper.java:433)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.checkForTranslation(AbstractJSPExtensionServletWrapper.java:292)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:142)
at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionProcessor.handleRequest(AbstractJSPExtensionProcessor.java:337)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3622)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:927)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1566)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:175)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:455)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:384)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:272)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1527)

I have added the required jar files also. Could someone please help on this?


Thanks,
Rajesh.B
Claudiu Chelemen
Ranch Hand

Joined: Mar 25, 2011
Posts: 71

Hi Rajesh

Did you import the SimpleEmail class in your jsp page ?

e.g.
<%@ page import="org.apache.commons.mail.SimpleEmail"%>

Claudiu
Rajesh Balu
Ranch Hand

Joined: Nov 07, 2011
Posts: 55
Yes, i have imported the SimpleEmail class.

<%@page import="org.apache.commons.mail.SimpleEmail"%>

Claudiu Chelemen
Ranch Hand

Joined: Mar 25, 2011
Posts: 71

Then the webserver / application server does "see" the apache commons jar.
What server are you running your app on and where did you put the apache jar ?

Claudiu
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Why one earth would you move working code form a Java class where it belongs, to a JSP where Java code is a very poor practice? Move it back to a class and never use Java in a JSP.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Furthermore, with a separate class, you can design it so it can be tested outside the servlet/jsp environment by adding a main method.

There are enough complexities in servlet/jsp - test everything you can outside that environment.

Bill
Rajesh Balu
Ranch Hand

Joined: Nov 07, 2011
Posts: 55
Claudiu,

My application in running in WAS server and i have placed the library in the library folder of the application..


Bear Bibeault,

I have tried with the JSP and servlets and i faced the mentioned issues. So only i moved on to Java code.



Thanks,
Rajesh.B
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SimpleEmail through JSP