Solved

Java Report Alignment problem

Posted on 2011-09-26
12
220 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

Suggested Solutions

Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video teaches viewers about errors in exception handling.
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 …

710 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