Solved

Java Report Alignment problem

Posted on 2011-09-26
12
214 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
  • 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

821 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