0

I'm trying to send mail using form via the JavaMail API. I have created a simple jsp page with my servlet class as the form action, a java class as the Model. However each time I run the Jsp page to test, it shows a 404 page, saying requested resource not available when I click the "Submit" button on the form instead of redirecting to servlet.

I thought this could be a servlet mapping problem so I manually registered the servlet in a web.xml file I created in NetBeans but it's still not working.

The code in the servlet class is:

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
 version="3.1">
<display-name>mailservlet</display-name>
<description>

</description>

<servlet>
    <servlet-name>mailservlet</servlet-name>
    <servlet-class></servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>mailservlet</servlet-name>
    <url-pattern>/mailservlet</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>

mailservlet is the name of the servlet class.

Any suggestions on what else to do would be appreciated.

Vanessa
  • 43
  • 3
  • 12

2 Answers2

1

You need to put the class name and package in the servlet-class, otherwise it won't know what class to use. e.g:

<servlet-class>mypackage.myclass</servlet-class>
C.Gibby
  • 115
  • 1
  • 7
1

You need to add the fully qualified name of the servlet class

<servlet-class>com.sample.domain.test.MailServlet</servlet-class>

Then you need to do a post or get request to this resource, e.g.

<form action="/contextroot/mailservlet" method="get">

in your jsp page

Guenther
  • 2,035
  • 2
  • 15
  • 20