Servlet não funciona no IE. Por que?[OFF-Resolvido]

6 respostas
paulofafism

Pessoal estou tendo o seguinte problema não estou conseguindo executar um servlet no IE. Mas eu consigo executar no FireFox. alguém tem alguma ideia do que pode ser?

<form id = "formLogin" name="login" method="post" action="AdminServlet">            
        <table width="20%" border="1" align="center">                  
             <tr>
                <td colspan="2">
                     <div align="center">Login</div>
              </td>
         </tr>
         
         <tr>
            <td width="8%">Usuário</td>
                <td width="92%">
                    <input type="text" name="logon" size="50" maxlength="50">
                </td>
         </tr>      
         
    
         
         <tr>
            <td width="8%" class="textoCabecalhoForm"> Senha</td>
                <td width="92%">
                    <input type="password" name="senha" size="10" maxlength="10">
            </td>
         </tr>
     </table>
            <p align="center">
                <input type="submit" name="Login" value="Login">
                <input type="reset" name="Limpar" value="Limpar"
                <input type="hidden" name="metodo" value="login">
            </p>
    </form>

6 Respostas

maiconramones

Cade a tua servlet??? Está aparecendo alguma mensagem de erro??

Abraço

leofernandesmo

Bom.
1 - O problema é neste JSP que vc colou ou após o envio da solicitação?
2 - O que acontece. Da alguma msg de erro ou o servlet não é executado.?

Ps -> Cole o servlet para a gente ver.

paulofafism

Segue abaixo o código da minha servlet

O Servlet funciona da seguinte maneira:

Esta linha de codigo
armazena o valor que eu quero que meu servlet execute. Por exemplo o valor é "login" então ele irá executar outro servlet reponsável por realizar o login.

No FireBox funciona sem problemas. Mas parece que o IE não consegue capturar o valor do código html

Exception retorna no IE
Comando executado: home
oberon.exception.CommandException: Identificador de comando inválido!
        at oberon.servlet.AdminServlet.lookupCommand(AdminServlet.java:68)
        at oberon.servlet.AdminServlet.service(AdminServlet.java:77)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:619)
[quote]



 [b]<input type="hidden" name="metodo" value="login">[/b]

[code]
     </table>
            <p align="center">
                <input type="submit" name="Login" value="Login">
                <input type="reset" name="Limpar" value="Limpar"
                [b]<input type="hidden" name="metodo" value="login">[/b]
            </p>
    </form>
import java.io.*;
import java.net.*;
import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;

import oberon.command.Command;
import oberon.command.LoginCommand;
import oberon.command.LogoutCommand;
import oberon.exception.CommandException;     
import oberon.domain.Usuario;

/**
 * Este Servlet funciona como um controlador de comandos. O método <code>Service</code> 
 * pega o processador de comandos apropriado na lista de comandos e chama o seu 
 * método <code>execute</code>, depois redireciona a requisição para a página apropriada.
 * 
 * @version 1.0
 * @author Paulo Vinícius Moreira Dutra
 */
public class AdminServlet extends HttpServlet {
   
    //Armazena as referências dos comandos
    private HashMap<String, Object> commands;      
    
    private String errorPage = "/error_connection.jsp";
    
    public AdminServlet(){
        super();
    }
    
    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        initCommands();
    }    
    
    /**
     * Associa cada indicador de comando a instncia de uma classe de comando
     * (que  pre-configurada com a o nome do arquivo da tela de destino).
     */
    private void initCommands() {
        commands = new HashMap<String, Object>(); //chave: <metodo, classe de comando associado>
        commands.put("login", new LoginCommand("/sejabemvindo.html"));
        commands.put("logout", new LogoutCommand("/index.jsp"));
    }    
   /**
     * Pega o objeto apropriado o HashMap e fornece um método de fábrica.
     * @param cmd
     * @return
     * @throws CommandException
     */
    private Command lookupCommand(String metodo) throws CommandException {        
        if (metodo == null)
            metodo = "home";
        System.out.println("Comando executado: " + metodo.toLowerCase());
        if (commands.containsKey(metodo.toLowerCase()))
            return (Command) commands.get(metodo.toLowerCase());
        else
            throw new CommandException("Identificador de comando inválido!");
    }    
    
    @Override
    public void service(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {        
        String next;        
        HttpSession session = request.getSession();       
        try {         
            Command command = lookupCommand(request.getParameter("metodo"));
            next = command.execute(request);
            //CommandToken.set(request);
        } catch (CommandException ce) {
            request.setAttribute("javax.servlet.jsp.jspExecution", ce);
            next = errorPage;
            ce.printStackTrace();
        } 
      //  response.sendRedirect(next);
        RequestDispatcher rd = getServletContext().getRequestDispatcher(next);
        rd.forward(request, response);        
    }                
        
    /** 
    * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
    * @param request servlet request
    * @param response servlet response
    */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            /* TODO output your page here
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet AdminServlet</title>");  
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet AdminServlet at " + request.getContextPath () + "</h1>");
            out.println("</body>");
            out.println("</html>");
            */
        } finally { 
            out.close();
        }
    } 

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
    * Handles the HTTP <code>GET</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    /** 
    * Handles the HTTP <code>POST</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
    * Returns a short description of the servlet.
    */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}
paulofafism

Detalhe ja ia me esquecendo o erro acontece após o envio do comando. No FireFox funciona mais no IE não

maiconramones

Cara está chegando a tua string metodo como null?? Uma coisa que tu pode testar é o seguinte: fechar a tag input que esta aberta, pode ser que ie esteja se perdendo nisso, não tenho certeza é um chute…

<input type="submit" name="Login" value="Login" /> <input type="reset" name="Limpar" value="Limpar" /> <input type="hidden" name="metodo" value="login" />

paulofafism

Maicon e isso mesmo. com certeza foi uma falta de atenção minha na hora de digitar o html
Obrigado
Abraços

Criado 4 de abril de 2008
Ultima resposta 4 de abr. de 2008
Respostas 6
Participantes 3