Hi I am trying to send the mail to client containing message as a data retrieved from database in table format. I am retrieving data in below servlet. now i want to send all this data in jsp page in table format. from this page i am sending all this data to a servlet where i wrote the code to send mail How can I send all this data in jsp page so that it is available in jsp in table format? if i am stiring all variable in session but how i can use them in value in jsp page
Here is an servlet page.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.student.igidr.test;
import java.io.*;
import java.net.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
*
* @author user1
*/
public class tabledata extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException{
HttpSession session = request.getSession(true);
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
int QNO;
String noA,noB,noC,noD;
String ID=request.getParameter("id");
String EVENTID=request.getParameter("event");
String connectionURL = "jdbc:mysql://localhost :3306/mynewdatabase";
Statement st = null;
Statement st1 = null;
ResultSet rs=null;
ResultSet rs1=null;
Connection connection=null;
try{
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(connectionURL, "root", "root123");
st = connection.createStatement();
rs = st.executeQuery("SELECT * FROM Questionbank where Questionid='"+ID+"'");
while(rs.next()){
String no=rs.getString("Qserialno");
session.setAttribute("NO", no);
String name=rs.getString("questionname");
session.setAttribute("NAME", name);
st1 = connection.createStatement();
rs1 = st1.executeQuery("SELECT * FROM Questionbank where Questionid='"+ID+"'");
try{
rs1=st1.executeQuery("select count(*) as total from final where questionid='"+ID+"'and Eventid='"+EVENTID+"'and Qserialno='"+rs.getString("Qserialno")+"'and Answer='A'");
rs1.next();
noA=rs1.getString("total");
session.setAttribute("NOA",noA);
rs1=st1.executeQuery("select count(*) as total from final where questionid='"+ID+"'and Eventid='"+EVENTID+"'and Qserialno='"+rs.getString("Qserialno")+"'and Answer='B'");
rs1.next();
noB=rs1.getString("total");
session.setAttribute("NOB",noB);
rs1=st1.executeQuery("select count(*) as total from final where questionid='"+ID+"'and Eventid='"+EVENTID+"'and Qserialno='"+rs.getString("Qserialno")+"'and Answer='C'");
rs1.next();
noC=rs1.getString("total");
session.setAttribute("NOC",noC);
rs1=st1.executeQuery("select count(*) as total from final where questionid='"+ID+"'and Eventid='"+EVENTID+"'and Qserialno='"+rs.getString("Qserialno")+"'and Answer='D'");
rs1.next();
noD=rs1.getString("total");
session.setAttribute("NOD",noD);
}
catch (Exception e){
pw.println(e);
}
finally
{
if (rs1 != null)
{
rs1.close();
rs1 = null;
} if (st1 != null)
{
st1.close();
st1 = null;
}
}
}
} catch (Exception e){
pw.println(e);
}
}
}
Now here is an jsp page.
<table align="center" width="50%" cellspacing="0" cellpadding="0" border="1" borderColor=#D2691E>
<form name="sendmail" action="/student/servletmail" method="POST">
<tr class="CellColor">
<td>To</td>
<td class="CellColor" width="1%">
:
</td>
<td class="CellColor">
<input type="text" name="to" size="25" value="">
</td>
<td>From</td>
<td class="CellColor" width="1%">
:
</td>
<td class="CellColor">
<input type="text" name="from" size="25" value="">
</td>
</tr>
<input type="hidden" name="message" value[B]="??????">// what will be value here[/B]
<tr class="CellColor">
<td class="CellColor" colspan="9" align="center">
<input type="submit" name="tn1" value="Send" >
</td>
</tr>
</form></table>
And here is an servlet from I am trying to send the mail.
package com.student.igidr.test;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.mail.*;
import javax.mail.event.*;
import javax.mail.internet.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
*
* @author user1
*/
public class servletmail extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out=response.getWriter();
response.setContentType("text/html");
try
{
Properties props=new Properties();
props.put("mail.smtp.host","webmail.igidr.ac.in"); // 'localhost' for testing
Session session1 = Session.getDefaultInstance(props,null);
String s1 = request.getParameter("to");
String s2 = request.getParameter("from");
//String s3 = request.getParameter("sub");
String s4 = request.getParameter("message");
// out.println(s4);
Message message =new MimeMessage(session1);
message.setFrom(new InternetAddress(s2));
message.setRecipients
(Message.RecipientType.TO,InternetAddress.parse(s1,false));
// message.setSubject(s3);
message.setText(s4);
Transport.send(message);
out.println("mail has been sent");
}
catch(Exception ex)
{
System.out.println("ERROR....."+ex);
}
}
}
Problem is how can i use value of message field in jsp page as all the data retrieved from in table format only. this table contain analysis of perticular event and i want to send such tabular format data to the respective user.
Any suggestion is highly appreciated.
Thanks and Regards
Haresh