“NetworkError:404找不到servlet

时间:2015-11-18 18:02:45

标签: java ajax jsp servlets

我正在尝试将我的JSP与我的Servlet进行通信。出现此错误“NetworkError:404 Not Found

loteCadastro.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">

    <!-- bootstrap -->
    <link rel="stylesheet" href="css/bootstrap.min.css">
      <script src="js/jquery.js"></script>
      <script src="js/bootstrap.min.js"></script>
<script type="text/javascript">

function enviar(){
    //Estou pegando as informaçoes do formulário
    var codLote = $("#idLote").val();
    var descricaoLote = $("#descricao").val();
    var dataCricao = $("#data").val(); 
    var codPropriedade = 1;
    var dataCricao = $("#faseLote").val();

    alert(descricaoLote);

    $.ajax({
        type:"POST",
        data:{codLote:codLote, descricaoLote:descricaoLote, dataCricao:dataCricao, codPropriedade:codPropriedade, dataCricao:dataCricao},
        //dataType: "json",
        url:"LoteController",

        success: function(result){
            alert(result.length);
            $("#resultado").html(result);
        }
    });
}
</script>
</head>
<body>
    <div class="container">

        <div class="page-header"><h1>Cadastro de Lote</h1></div> 

        <form class="form-horizontal" role="form"> 

        <div class="form-group">
          <label class="control-label col-sm-2" for="codigo">Código:</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" id="idLote" placeholder="01">
          </div>
        </div>

        <div class="form-group">    
          <label class="control-label col-sm-2" for="descricao">Descrição:</label> <!-- tag <label> é apenas um espaço para colocar o nome do campo -->
          <div class="col-sm-10">
            <textarea class="form-control" rows="5" id="descricao" placeholder="teste"></textarea> <!-- textarea campo maior para mais informações-->
          </div>
        </div>

      <div class="form-group">
          <label class="control-label col-sm-2" for="data">Data Criação:</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" id="dataCriacao" placeholder="21/10/2015">
          </div>
        </div>

       <div class="form-group">
      <label class="control-label col-sm-2" for="fase">Fase:</label>
      <div class="col-sm-10">
        <select id="faseLote" class="form-control"> <!-- select -->
          <option>option 1</option>     <!-- option são exeplos, vão ser populados confirmoações do BD -->
          <option>option 2</option>
          <option>option 4</option>
        </select>
      </div>
    </div>

        <div class="form-group">        
          <div class="col-sm-offset-2 col-sm-10">
            <input type="submit" class="btn btn-default"; onclick="enviar()"; return false;">Salvar</input>
            <input type="button"  class="btn btn-danger" onclick="location.href='loteDashboard.jsp';">Cancelar</input>
          </div>
        </div>
      </form>
    </div>
</div> <!-- fim container principal -->
</body>
</html>

LoteController.java

@WebServlet("/LoteController")
public class LoteController extends HttpServlet {
    private static final long serialVersionUID = 1L;
    public LoteController() {
        super();
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/plain");
        Integer codLote = Integer.parseInt(request.getParameter("codLote"));
        int codPropriedade = Integer.parseInt(request.getParameter("codPropriedade"));
        String comentario = request.getParameter("descricaoLote");
        String dataCriacao = request.getParameter("dataCriacao");
        System.out.println("Chegou: " + comentario);
        Date date = new Date();
        Lote lote = new Lote();
        lote.setCodLote(codLote);
        lote.setDescricaoLote("Teste fsdaf");
        lote.setCodPropriedade(codPropriedade);
        lote.setDataCriacao(date);
        lote.setDataEncerramento(date);
        LoteDAO loteDao = new LoteDAO(HibernateUtil.getSessionFactory(), lote.getClass());
        loteDao.Salvar(lote);
        response.getWriter().append("Served at: ").append(request.getContextPath());
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/plain");
        Integer codLote = Integer.parseInt(request.getParameter("codLote"));
        int codPropriedade = Integer.parseInt(request.getParameter("codPropriedade"));
        String comentario = request.getParameter("descricaoLote");
        String dataCriacao = request.getParameter("dataCriacao");
        System.out.println("Chegou: " + comentario);
        Date date = new Date();
        Lote lote = new Lote();
        lote.setCodLote(codLote);
        lote.setDescricaoLote("Teste fsdaf");
        lote.setCodPropriedade(codPropriedade);
        lote.setDataCriacao(date);
        lote.setDataEncerramento(date);
        LoteDAO loteDao = new LoteDAO(HibernateUtil.getSessionFactory(), lote.getClass());
        loteDao.Salvar(lote);
    }
    public static void insert(Lote lote) throws Exception {
        Session session = HibernateUtil.getSessionFactory();
        Transaction tx = session.beginTransaction();
        session.save(lote);
        tx.commit();
        session.close();
    }
}

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" 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>sysbovino-pds</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

</web-app>

我正在使用servlet 3.0,我在web.xml中尝试了map并给了我同样的问题。

我搜索了解决方案但没有找到任何结果。

0 个答案:

没有答案