Solved

Java Report Alignment problem

Posted on 2011-09-26
12
196 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
 
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now