File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes newsletter module Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "newsletter module" Watch "newsletter module" New topic

newsletter module

azhar bharat
Ranch Hand

Joined: Jul 17, 2006
Posts: 87
I want to create a newsletter module from where i can send newsletters to multiple emails. The images will be embedded in the email.

Now, let me describe the problem:
The body for the email(html code) is pasted into the text area.
Now, to embed the image, i need to upload the image to the server.
How do i upload the image, probably after extracting the src from the image tag?
Is it possible since the field is not of file type?
If my approach is not correct what is a possible approach?
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3704

You could parse the HTML that is uploaded either manually or using an XML validator (although good luck handling poorly formatted HTML). Its a good idea especially if you want to make sure people don't upload malicious code, as an example, such parsers usually remove all but the most basic HTML tags like bold/italic/etc. One its parsed, finding the img tag is then trivial.

Another method is just to convert the entire html file into a single string and try using regular expressions to match an image tag.

Really for uploading files though, I recommend a form upload button to explicitly upload the files. There's no telling how many files or how big they will be if you start uploading from external sites.
[ August 16, 2006: Message edited by: Scott Selikoff ]

My Blog: Down Home Country Coding with Scott Selikoff
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3704

BTW if you are going to upload the files and save them locally, you're going to need to re-parse the HTML anyway to replace the original URL with a local URL.
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
you might find this helpful

MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
azhar bharat
Ranch Hand

Joined: Jul 17, 2006
Posts: 87
Thanks for the replies.
Actually I can extract the file details from the html. That is not the problem now.
My problems are
after i extract the file details, what do i do next? ie how do i upload the files given in the html?
If it is not possible, please suggest a workaround.
As i said the field is just textarea and not file field.
I have never done this before so any help is welcome.
[ August 16, 2006: Message edited by: azhar bharat ]
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Even if you know the location of an image file on the client machine, you're not going to be able to get the browser to upload it to you without the user explicitly clicking on a 'file' input button, selecting the image and submitting your form.
Browser makers take great care to insure that this is the only way an upload is performed.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: newsletter module