Java Servlet: Send form data by email. (Netbeans)

I'm using Netbeans to write a simple program, but I'm a little confused and would like some help. Already made a lot of research but servlets are new to me.

I have an Java web app created, simple website coded in html that must gather information from a form and send it to an specific email. The email is always the same, and will be stored in the submit button in the form.

Everything is fine with the html code, the problem is that once I create the servlet I don't know how to link it to the html code or form in it.

Any help will be good.

Answers


I don't know how to link it to the html code or form in it.

Map the servlet on an URL pattern in web.xml or by @WebServlet annotation. Let the action attribute of the <form> point to exactly that URL. Assuming that form's method is POST, collect the request parameters in doPost() method of the servlet. Finally do your job with them the usual Java way.

So:

<form action="servletURL" method="post">
    <input type="text" name="foo" />
    ...
</form>

with in doPost() method

String foo = request.getParameter("foo");
// ...
See also:

Sending a mail in a servlet is not different from in a plain vanilla Java class with a main() method. So you don't necessarily need to focus on "sending a mail with servlet" for which you won't find much examples, but just on "sending a mail with java" for which you will certainly find much examples.

See also:

you can find example here for servlet and jsp.


Please refer to this link : http://www.servletworld.com/servlet-tutorials/simple-servlet-example.html In the doPost() method, they are generating an html response. In addition the the HTML response, you can write the code to send email. For that, please refer this link: http://www.javapractices.com/topic/TopicAction.do?Id=144


Need Your Help

How to check modified value in a model's before_save callback?

ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.1

How can I read the value that a controller has set in a before_save callback?

Entity Framework many to many relationship between 3 tables

asp.net sql-server entity-framework

I had a scenario where an Organization Works in some cities of a state,In this situation I needed to relate Organization with City with a many to many relationship. I made a table with Composite key

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.