Piccolo problema Servlet per Neofiti

di il
1 risposte

Piccolo problema Servlet per Neofiti

Ciao a tutti. Da un'ora sto impazzendo per un programmino semplice ( sto appena imparando java).
In Teoria da una pagina jsp voglio collegarmi a un servlet attraverso il web.xml.
In pratica non va e non capisco!!!!

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>MailProject</display-name>
  
  <welcome-file-list>
    <welcome-file>home.jsp</welcome-file>
  </welcome-file-list>
  
   <display-name>Servlet</display-name>     
    <description>Primo</description>
            
    <servlet> 
        <servlet-name>sendMail</servlet-name> 
        <servlet-class>sendMail</servlet-class> 
    </servlet> 
    <servlet-mapping>
        <servlet-name>sendMail</servlet-name>
        <url-pattern>/sendMail</url-pattern>   <!--  richiamo la Servlet http://localhost:8080/Servlets/servlet/Esempio -->
    </servlet-mapping>     
  
</web-app>


la jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	
	  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
	  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
	  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
	  
	  <!-- Latest compiled and minified CSS -->
	  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
	  <!-- Optional theme -->
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
	  <!-- Latest compiled and minified JavaScript -->
	  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
	  
	  <title>Insert title here</title>
</head>
<body>
	<form method="post" border="1" action="sendMail" >
				<fieldset>
					<legend>InfoMail</legend>
					
					<div class="form-group">
				    	<label for="exampleInputEmail2">Email</label>
				    	<input type="email" class="form-control" id="exampleInputEmail2" placeholder="jane.doe@example.com">
				    </div>		
					<br>
					
					<div class="form-group">
				    	<label for="exampleInputEmail2">Object</label>
				    	<input name="object" type="text"class="form-control" placeholder="Object" maxlength="50">
				    </div>		
		
					<br>
					
					<div class="form-group">
				    	<label for="exampleInputEmail2">Object</label>
				    	<input name="body" type="text" class="form-control" placeholder="Body of Mail" size="40">
				    </div>		
				    
				    <div class="btn-group" role="group" aria-label="...">
  						<button type="submit" class="btn btn-default" >Send</button>
  					</div>
  					
				</fieldset>
				
			</form>
	</body>
</html>

la servlet

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



public class sendMail extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		System.out.println("SERVLET");
	}

}
[Allego anche l'immagine delle cartelle.

Qualcuno sa dirmi dove sbaglio? in pratica quando clicco sulla submit mi da errore 404 . non trova l servlet

GRAZIE MILLE
Allegati:
17914_204d3e43de0c44406c573a649d49bf4f.png
17914_204d3e43de0c44406c573a649d49bf4f.png

1 Risposte

  • Re: Piccolo problema Servlet per Neofiti

    Ciao,
    controlla il file xml di configurazione:

    qua definisci le servlet
    
    <servlet>
            <servlet-name>form</servlet-name>
            <servlet-class>servlet.form</servlet-class>
    </servlet>
    
    qua l associazione servlet/jsp
    
    <servlet-mapping>
            <servlet-name>form</servlet-name>
            <url-pattern>/form</url-pattern>
    </servlet-mapping>
    
Devi accedere o registrarti per scrivere nel forum
1 risposte