Request recebe valore null

10 respostas
java
D

Amigos, o request está retornando null, e eu não estou conseguindo ver o que está errado, poderiam me dar uma ajudinha, provavelmente é uma coisa boba mais não estou conseguindo ver

<div id="Layer2">

		<form action="/RelatorioNC/pesquisaSos" method="post">

			<table width="700" height="132" align="center">
				<td width="12" height="82" align="left">&nbsp;</td>
				<td width="248">Setor:
					<div class="styled-select">
						<div class="campo">
							<select style="width: 200px" name="cmbSetor" size="1">
								<option>Selecione...</option>
								<option value=1>------------- TODOS SETORES ----------</option>
								<c:forEach var="setores" items="${listaSetores}">
									<option value="${setores.sSetores}">${setores.sSetores} - ${setores.sNome}</option>
								</c:forEach>
							</select>
						</div>
					</div>
				</td>
				<td height="82" align="right">&nbsp;</td>
				<td>Data Inicio:
					<div class="campo">
						<input type="date" id="dtaIni" name="dtaInicio" size="25">
					</div>
				</td>
				<td align="right">&nbsp;</td>
				<td>Data Final:
					<div class="campo">
						<input type="date" id="dtaFim" name="dtaFim">
					</div>
				</td>

				<td> <a href="javascript:abreDetalhes()"><img src="imagens/pesquisa.png" width="40" height="40"></a> </td>
			</table>
		</form>
	</div>

`
package br.com.montreal.relatorio.controller;

import java.io.IOException;

import java.sql.SQLException;

import java.util.ArrayList;

import java.util.List;
import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;
import br.com.montreal.relatorio.cliente.RelatorioSos;

import br.com.montreal.relatorio.entidade.BeanPesquisaSos;

import br.com.montreal.relatorio.entidade.RelatorioPesquisaSos;

import br.com.montreal.relatorio.enumeracao.TipoPesquisa;

import br.com.montreal.relatorio.excecoes.CampoVazio;

@WebServlet(urlPatterns = “/pesquisaSos”)
public class PesquisaSos extends HttpServlet {

private static final long serialVersionUID = 1L;
private RelatorioSos relatorioCliente = new RelatorioSos();
private BeanPesquisaSos objPesquisa = null;
private List<RelatorioPesquisaSos> listaSos = new ArrayList<RelatorioPesquisaSos>();
private StringBuilder html = null;
 


@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
	this.doPost(request, response);

}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	String acao = request.getParameter("acao");


	if ("result".contains(acao)) {

		try {

			objPesquisa = new BeanPesquisaSos();
			objPesquisa.setsSetor(request.getParameter("cmdSetor"));
			objPesquisa.setsDataInicial(request.getParameter("dtaInicio"));
			objPesquisa.setsDataFinal(request.getParameter("dtaFim"));

			TipoPesquisa tipoPesquisa = TipoPesquisa.getTipoPesquisa(objPesquisa.getsSetor());

			listaSos = relatorioCliente.listaCompletaSos(objPesquisa,tipoPesquisa);
			
			request.setAttribute("listaSos", listaSos);

			html = new StringBuilder();
			
			html.append("<table id=\"t01\" width=\"750\" align=\"center\">").append("\r\n");
			html.append("<tr align=\"center\" bgcolor=\"#F58634\">").append("\r\n");
			html.append("<th>SOLIC</th>").append("\r\n");
			html.append("<th>SETOR</th>").append("\r\n");
			html.append("<th>ROTINA</th>").append("\r\n");
			html.append("<th>DATA_DE_ABERTURA</th>").append("\r\n");
			html.append("<th>HORA_DE_ABERTURA</th>").append("\r\n");
			html.append("<th>PRAZO_DATA_ORIGINAL</th>").append("\r\n");
			html.append("<th>PRAZO_HORA_ORIGINAL</th>").append("\r\n");
			html.append("<th>DATA_DE_ENCERRAMENTO</th>").append("\r\n");
			html.append("<th>HORA_DE_ENCERRAMENTO</th>").append("\r\n");
			html.append("<th>RESPONSAVEL</th>").append("\r\n");
			html.append("</tr>").append("\r\n");
			
			for (RelatorioPesquisaSos itensSOS : listaSos) {
				
				html.append("<tr>").append("\r\n");
				html.append("<td align=\"left\">" + itensSOS.getsSolic()             +"</td>").append("\r\n");
				html.append("<td align=\"left\">" + itensSOS.getsSetor()             +"</td>").append("\r\n");
				html.append("<td align=\"left\">" + itensSOS.getsRotina()            +"</td>").append("\r\n");
				html.append("<td align=\"left\">" + itensSOS.getsDataAbertura()      +"</td>").append("\r\n");
				html.append("<td align=\"left\">" + itensSOS.getsHoraAbertura()      +"</td>").append("\r\n");
				html.append("<td align=\"left\">" + itensSOS.getsPrazoDataOriginal() +"</td>").append("\r\n");
				html.append("<td align=\"left\">" + itensSOS.getsPrazoHoraOriginal() +"</td>").append("\r\n");
				html.append("<td align=\"left\">" + itensSOS.getsDataEncerramento()  +"</td>").append("\r\n");
				html.append("<td align=\"left\">" + itensSOS.getsHoraEncerramento()  +"</td>").append("\r\n");
				html.append("<td align=\"left\">" + itensSOS.getsResponsavel()       +"</td>").append("\r\n");
				html.append("</tr>").append("\r\n");	
				
			}
			
			html.append("</table>").append("\r\n");
			response.setContentType("text/html");

			response.getWriter().write(html.toString());

			return;

		} catch (SQLException e) {
			e.printStackTrace();

		} catch (CampoVazio e1) {
			e1.printStackTrace();

		}

	}

}

}

`

pesquisaSOS.jsp (3.7 KB)

10 Respostas

L

Mostra aí como você adquire esse request.

D

ta no jsp acima os três trechos dos campos que recupero

darklordkamui

aonde está o seu botão que envia a informação?

D

envio através do javascript

darklordkamui

posta o seu js por favor

D

coloquei o arquivo em anexo, por que não estou conseguindo colocar o javascript

darklordkamui

olha eu vi seu js…

você não fez o submit do form,

anterior, por isso não enviou as informações para o controller,
tenta algo assim…
coloca um id no seu form e executa para ver…

document.getElementById(“meuForm”).submit();

D
<form action="/RelatorioNC/pesquisaSos" method="post" id="pesquisa" enctype= "multipart/form-data">

dessa forma?

function abreDetalhes() {

	$.ajax({
		url : "/RelatorioNC/pesquisaSos?acao=result", success : function(result) {
			document.getElementById("pesquisa").submit();
			$("#div1").html(result); //Receber tabela carregada na PesquisaPedidos
			
			$("#dialog").dialog("open"); //Abre caixa de dialogo Jquery
		}
	});
}

dessa forma não funcionou onde coloco esse document

darklordkamui

tenta algo assim… eu não tenho muita experiencia com Jquery, mas basicamente isso deveria funcionar…

function abreDetalhes() {

$("#pesquisa").submit(function(e) {

$.ajax({

url : /RelatorioNC/pesquisaSos?acao=result, success : function(result) {

$("#div1").html(result); //Receber tabela carregada na PesquisaPedidos
$("#dialog").dialog("open"); //Abre caixa de dialogo Jquery
	}
});
e.preventDefault();

});

}
D

funcionou não, o botão para de funcionar.

Criado 29 de janeiro de 2016
Ultima resposta 1 de fev. de 2016
Respostas 10
Participantes 3