This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SimpleEmail through JSP

 
Rajesh Balu
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, i have imported the SimpleEmail class.

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

 
Claudiu Chelemen
Ranch Hand
Posts: 75
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic