1

I am having a simple Servlet that send emails and an html-form:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>A form</title> </head> <body> <form action="feedback" method="post"> <!-- Simple text field --> <label for="name">Name </label> <input type="text" name="name"/> <br/> <!-- Email --> <label for="email">Email </label> <input type="email" name="email"/> <br/> <!-- Textarea --> <label for="description">Description </label> <textarea name="description" cols="50" rows="5">Type your comment here</textarea> <br/> <input type="submit" name="submit" value="Send Request"/> </form> </body> </html> 

In the web.xml Folder I registered and mapped the servlets. But when I press the send Button I just get:

HTTP ERROR 404

Problem accessing /feedback. Reason:

NOT_FOUND 

Where is still my problem?

--UPDATE-- http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">

<!-- Servlets --> <servlet> <servlet-name>FeedbackServlet</servlet-name> <servlet-class>org.wunderapps.mailservice.server.FeedbackServlet</servlet-class> </servlet> <servlet> <servlet-name>TestAppServlet</servlet-name> <servlet-class>org.wunderapps.mailservice.server.TestAppServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>FeedbackServlet</servlet-name> <url-pattern>/wunderapps_mail_service/mail</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>TestAppServlet</servlet-name> <url-pattern>/wunderapps_mail_service/test</url-pattern> </servlet-mapping> <!-- Default page to serve --> <welcome-file-list> <welcome-file>Wunderapps_mail_service.html</welcome-file> </welcome-file-list> 

Servlet:

package org.wunderapps.mailservice.server; import java.io.IOException; import java.util.Properties; import javax.mail.Message; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @SuppressWarnings("serial") public class FeedbackServlet extends HttpServlet { @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String name = req.getParameter("name"); String description = req.getParameter("description"); String email = req.getParameter("email"); Properties props = new Properties(); Session session = Session.getDefaultInstance(props, null); String msgBody = name + " :Name" + "\n" + description + " :Description" + "\n" + email + " :EMAIL"; try { Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress("[email protected]", "it works")); msg.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]", "Your name")); msg.setSubject("Bestellung"); msg.setText(msgBody); Transport.send(msg); } catch (Exception e) { resp.setContentType("text/plain"); resp.getWriter().println("Something went wrong. Please try again."); throw new RuntimeException(e); } resp.setContentType("text/plain"); resp.getWriter().println( "Thank you for your feedback. An Email has been send out."); } } 
10
  • Add more details, share your POST Url, Web.xml Commented Jul 13, 2012 at 15:14
  • Here is the servlet and the web.xml! Commented Jul 13, 2012 at 15:21
  • Change <form action="feedback" method="post"> to <form action="/wunderapps_mail_service/mail" method="post"> it should work Commented Jul 13, 2012 at 15:22
  • Thx for your answer but it still says: NOT FOUND... Do you have an idea why? Commented Jul 13, 2012 at 15:28
  • Have you tried changing in web.xml??? Commented Jul 13, 2012 at 15:30

1 Answer 1

1

From your web.xml it looks there is some problem in url pattern so only it gives 404 Error. Change <form action="feedback" method="post"> to <form action="/wunderapps_mail_service/mail" method="post"> Or alternatively you can change web.xml too.

<servlet-mapping> <servlet-name>FeedbackServlet</servlet-name> <url-pattern>/feedback</url-pattern> </servlet-mapping> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.