Judy Liddle

Greenhorn
+ Follow
since Sep 28, 2000
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Judy Liddle

I am grabbing data from a hashmap.
I am not sure if I am most efficiently getting int values.
I am currently casting to (Integer) and then using intValue().
Integer iNMC = (Integer) row.get("NMC");
int FMC = iFMC.intValue();
Is there a more efficient way to do this?
21 years ago
I am unable to catch an exception.
Class1 is calling a method in Class2, an exception is caught and thrown, and this is not being caught in Class1.
public Class1 {
...
try {
Class2 class2 = new Class2();
value = class2.method();
}
catch(Exception e){
System.out.println("This is not happening");
}
}
public class2 {
public synchronized List method() throws Exception {
try {
...
throw new Exception("Bad stuff.");
}
catch (Exception e){
System.out.println("An exception was thrown - this prints");
throw e;
}
finally {
return List;
}
}
21 years ago
My servlet is running, and not producing a page, just a blank screen. Im using JRUN and nothing is being logged to stdout.log.
(I had a test print mesg for when it starts)
I checked this site for a reason, and found that it could be from using instance variables inside my doPost. I am only using local variables.
Any suggestions?
21 years ago
If anyone else is interested in this question...
I found out that the smtp protocol (sun.net.smtp.SmtpClient)is one way to send mail through Java without using Java Mail API.
But the Smtp API does not seeem to support attachments.
public class sun.net.smtp.SmtpClient
extends sun.net.TransferProtocolClient {
public void closeServer()
throws IOException;
public void to(String)
throws IOException;
public void from(String)
throws IOException;
public PrintStream startMessage()
throws IOException;
public sun.net.smtp.SmtpClient(String)
throws IOException;
public sun.net.smtp.SmtpClient()
throws IOException;
public String getMailHost();
}
I found a great example that uses Java Mail to send an attachment.
// create mime message object
// set the required parameters
MimeMessage message = createMessage(to, cc, subject);

// create the message part
MimeBodyPart messageBodyPart = new MimeBodyPart();
//fill message
messageBodyPart.setText(msg);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// fill the array of files to be attached
File [] attachments = {
new File("x.txt"),
new File("y.htm"),
new File("z.jpg")
};
for( int i = 0; i < attachments.length; i++ )
{
messageBodyPart = new MimeBodyPart();
FileDataSource fileDataSource =new FileDataSource(
attachments[i]);
messageBodyPart.setDataHandler(new DataHandler(
fileDataSource));
messageBodyPart.setFileName(
attachments[i].getName());

multipart.addBodyPart(messageBodyPart);
}
// add the Multipart to the message
message.setContent(multipart);
// SEND THE MESSAGE
Transport.send( message );

21 years ago
I am currently using our server and mail host to send emails
via a socket. I am not trying to have a mail server, just the ability to send automated emails.
This works fine, but now I want to be able to add a file as an attachment.
Any suggestions?
21 years ago
I am modifying code which uses service() in its servlets.
In the past I have used doPost or doGet.
Could someone please explain the pros and cons of using service() instead of one of the other methods?
21 years ago
Wht is the difference in these two lines?
String s = "abc";
and
String s = new String("abc");
21 years ago
I understand that a final reference cannot be changed to reference something else. How is a static final reference different?
21 years ago