Solved

Java Report Alignment problem

Posted on 2011-09-26
12
228 Views
Last Modified: 2012-05-12
Hi Experts...
I have the code below which i use to send mail in html format.

The html report is getting prepared properly and the mail feature is working too.
The problem is :Say for example in my html report i have three HTML tables to be displayed they all take center alignment by default and appear one below the other.

When i explicitly add the left alignment code all the tables appear next to one another instead of one below the other.
Please help...
Code for html report:
                           String htmlString = "";
  htmlString += "<html>" + sep;
htmlString += "<head>" + sep;

htmlString += "<title>Your title</title></head><body>";


htmlString += "<table> <tr> <td> stuff</td><td>antother cell</td> </tr>" +
"<tr> <td> stuff</td><td>antother cell</td> </tr>" +
" <tr> <td> stuff</td><td>antother cell</td> </tr></table></body></html>";

Open in new window

Code for mailing:
public void sendEmail(String htmlString, Vector OAEmailAddresses,
                      Vector emailAddressesCC, String userAddress, String subject)
   {


 String adrFrom = userAddress;
      String signature = "";
     String sepp = System.getProperty("line.separator");


       String body = bodyText;

   InternetAddress [] intAdd;
    InternetAddress [] intAddcc;


  intAdd = new InternetAddress[OAEmailAddresses.size()];

    intAddcc = new InternetAddress[emailAddressesCC.size()];



       try {
  for(int j=0; j<OAEmailAddresses.size(); j++)
    intAdd[j] = new InternetAddress((String)OAEmailAddresses.elementAt(j));

    for(int j=0; j<emailAddressesCC.size(); j++)
    intAddcc[j] = new InternetAddress((String)emailAddressesCC.elementAt(j));



    Properties props = new Properties();

	
	props.put("mail.smtp.host", "mailhub.company.com");
	Session session = Session.getDefaultInstance(props, null);
	    Message msg = new MimeMessage(session);
	    msg.setFrom(new InternetAddress(adrFrom));
 

	    msg.setRecipients(Message.RecipientType.TO, intAdd);
            msg.setRecipients(Message.RecipientType.CC, intAddcc);
             msg.setSubject(subject );


        msg.setSentDate(new java.util.Date());

	    msg.setText(htmlString);
           msg.setHeader("Content-Type","text/html");  // this is important header

	    Transport.send(msg);
           }
       catch (Exception e) {System.out.println("Error sending e-mail : " + e.toString()); e.printStackTrace(); }
     System.out.println("E-mail message sent!");


}

Open in new window

0
Comment
Question by:gaugeta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
12 Comments
 
LVL 3

Expert Comment

by:anjos
ID: 36597777
Have you tried just adding a <br /> after each table?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36597852
In what place do you add left alignement code?
0
 

Author Comment

by:gaugeta
ID: 36597962
@for_yan:For example i have 2 tables i added the alignment code as shown.
Please help...
htmlString += "<table align=\"left\"> <tr> <td> stuff</td><td>antother cell</td> </tr>" +
"<tr> <td> stuff</td><td>antother cell</td> </tr>" +
" <tr> <td> stuff</td><td>antother cell</td> </tr></table></body></html>"; 

htmlString += "<table align=\"left\"> <tr> <td> stuff</td><td>antother cell</td> </tr>" +
"<tr> <td> stuff</td><td>antother cell</td> </tr>" +
" <tr> <td> stuff</td><td>antother cell</td> </tr></table></body></html>";

Open in new window

0
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 
LVL 47

Expert Comment

by:for_yan
ID: 36597978
In general you should not have </body></html> after each table - these usually come only in the end of the whole web page
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36597982
Why do you need to add align - what is it that you wanted to achieve with it?
0
 

Author Comment

by:gaugeta
ID: 36598057
@for_yan:Sorry for the above code.I just gave a sample of how it will look.
Each table does not have a </body></html> with it.

The valid code is shown below.

The effect i want to achieve is display table left aligned and and one below the other and not next to one another which is happening now.
Please help...
htmlString +="<left><table align=\"left\"><tr><td><h3>Final Status: Pass</h5></h3></td></tr></table></left>"; htmlString +="<left><table align=\"left\"><tr><td><h3>Final Status2: Pass</h5></h3></td></tr></table></left>";

Open in new window

0
 

Author Comment

by:gaugeta
ID: 36598274
@anjos:Yes i've added thr <br/> after each table.
Yet its not going to the next line.
Please help...
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 36602396
<div align="center"> before the firs <table>

then </div> after the </table>

then again <div align="center">  before the next <table>

and then again </div> after the last </table>

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 36602409
Does it send email ain any form?

If it does go to your emal - double click on it, then right-click in the middle and slecet "ViewSource"

Then you'll see notepad (or other editor ) window with html code.
Save the contents of that window to any .txt or .html file and post this file here - I'll correct your html
and tell you how to modify it to have them one under another

This deivision recommendation above shoudll work - if you understadn it from what I wrote above - you can give it a try
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36602417
Of course remove tehse tags <left> - theye dhouldf not be there <table align=\"left\"> - these should stay

htmlString +="<table align=\"left\"><tr><td><h3>Final Status: Pass</h5></h3></td></tr></table>"; htmlString +="<table align=\"left\"><tr><td><h3>Final Status2: Pass</h5></h3></td></tr></table>";

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 36602425
if the above post does not help then add disvisions like that:

htmlString +="<div><table align=\"left\"><tr><td><h3>Final Status: Pass</h5></h3></td></tr></table></div>"; htmlString +="<div><table align=\"left\"><tr><td><h3>Final Status2: Pass</h5></h3></td></tr></table></div>";

Open in new window



0

Featured Post

 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
A solution for Fortify Path Manipulation.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question