I want to redirect to a Servlet from my jsp page? How do I do it. Can I use dispatcher.forward() to call servlet from JSP as used to call jsp from a servlet ??
Swastik Dey wrote:You can simply use forward action
Thanks. I have to sent a mail to the user on successful registeration. In my registeration.jsp page, when the user is registered successfully, I call the following lines to call the servlet:
Results - on the jsp page, I don't see any thing, status bar says "Done", else blank page. If I remove the jsp:forward, it shows me Refistered Succeessful msg of the jsp page only.
I tried calling as "<%=request.getContextPath()%>/MailServlet" in jspforward, then it shows error on 2nd param saying jsp:param cannot be outside include, forward or params. I tried adding <jsp:params> </jsp:params> to cover all jap:param, but yet same error.
As said in the above post its not good to do processing in jsp, however as far as your problem is concerned, you are probably missing the flush with output stream writer, thats why its probably not displaying the output generated by servlet.
out.println("<br> Username has has been sent to your email address. You may now login.");
that means it was earlier generating the same exception in the servlet. Now coming to you problem you are connecting to localhost, so do you have a smtp server configured on your system?
Swastik Dey wrote:that means it was earlier generating the same exception in the servlet. Now coming to you problem you are connecting to localhost, so do you have a smtp server configured on your system?
Yes, i gave out.flush and it showed me the exception via servlet also.
.....javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25; nested exception is: java.net.ConnectException: Connection refused: connect
Swastik Dey wrote:do you have any smtp server configured and running locally, i mean on your local system?
I am connected to internet.
I gave props.put("mail.smtp.host", smtpServerIP");
yet it is throwing - .....javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25; nested exception is: java.net.ConnectException: Connection refused: connect
Prabhat Jha
Ranch Hand
Joined: Aug 13, 2007
Posts: 58
posted
0
Your smtp server is not configured or you are giving incorrect configuration details.
Smtp details can be obtained from your internet service provider.
Hope this helps.
Thanks,
Prabhat
SCJP 1.5, SCWCD 1.5, SCBCD 1.5
Bauke Scholtz
Ranch Hand
Joined: Oct 08, 2006
Posts: 2458
posted
0
Trupti Mehta wrote:
sending mail process is done is servlet only. Once registered successfully, then from my jsp page I am trying to call servlet to sent the mail.
The register process belongs in a Java class (a Servlet) as well.
Prabhat Jha wrote:Your smtp server is not configured or you are giving incorrect configuration details.
Smtp details can be obtained from your internet service provider.
Hope this helps.
I inquired the details and the one I had added is correct. But I have to provide username and password to use it from an external application. How can I set the username & password of the smtp server in the application?
amit daundkar
Ranch Hand
Joined: Jan 24, 2009
Posts: 47
posted
0
Trupti Mehta wrote:
Swastik Dey wrote:You can simply use forward action
Thanks. I have to sent a mail to the user on successful registeration. In my registeration.jsp page, when the user is registered successfully, I call the following lines to call the servlet:
Results - on the jsp page, I don't see any thing, status bar says "Done", else blank page. If I remove the jsp:forward, it shows me Refistered Succeessful msg of the jsp page only.
I tried calling as "<%=request.getContextPath()%>/MailServlet" in jspforward, then it shows error on 2nd param saying jsp:param cannot be outside include, forward or params. I tried adding <jsp:params> </jsp:params> to cover all jap:param, but yet same error.
Can help me out, where am I going wrong.
please get a copy of Head First -Servlet And Jsp - By Cathy Sierra.
you will get the answers in first few pages.
Please make sure you clear your concepts before going to coding.
Arvind Subramanian
Ranch Hand
Joined: Jul 25, 2008
Posts: 84
posted
0
amit daundkar is correct... your design is not a correct one. make it more simple.. forget to pass to servlet. Atleast create a class for mailing and call the method in the class directly from jsp. atleast it will be easy to maintain..
<%
MailUtils mail = new MailUtils(username,password,smtpserver);
mail.send(content,to,cc,bcc, subject)
%>
Remove the servletness from your current mail servlet and make it as simple class and call it.
but before that buy Headfirst Servlet & Jsp book... even i just passed 146th page currenlty
"Many of lifes failure are people who did not realize how close they were to success when they gave up."
-Thomas Edison
~ar~stutzen~
ujjwal soni
Ranch Hand
Joined: Mar 28, 2007
Posts: 390
posted
0
Hi,
Try doing telnet to smtp server.
Cheers!!!
Ujjwal B Soni <baroda, gujarat, india> <+919909981973>
"Helping hands are better than praying lips......"
Priya dharshini
Ranch Hand
Joined: Aug 06, 2005
Posts: 78
posted
0
Your SMTP server may not be configured. Try with SMTP server name which you knew working fine.
Thanks & Regards,
Priyadharshini . T
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.