0

I'm new in JSP and Servlets,

web.xml file

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <servlet>
        <servlet-name>LoginPage</servlet-name>
        <servlet-class>com.planner.servlet.LoginPage</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>LoginPage</servlet-name>
        <url-pattern>/LoginPage</url-pattern>
    </servlet-mapping>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContextBL.xml</param-value>
    </context-param>
</web-app>

index.jsp file

<%@ 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">
<title>Insert title here</title>
</head>
<body>
    <form method="POST" action="/LoginPage">
        <table border="1">
            <tr>
                <td>Login</td>
                <td><input type="text" name="login" />
                </td>
            </tr>
            <tr>
                <td>Senha:</td>
                <td><input type="password" name="pass" /></td>
            </tr>
            <tr>
                <input type="submit" value="Entrar" />
            </tr>
        </table>
    </form>
</body>
</html>

LoginPage.java

package com.planner.servlet;

import java.io.IOException;
import java.io.PrintWriter;

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 org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * Servlet implementation class LoginPage
 */
public class LoginPage extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoginPage() {
        super();
    }

    @Override
    public void init() throws ServletException {
        WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
        AutowireCapableBeanFactory bf = ctx.getAutowireCapableBeanFactory();

//      bf.autowireBean(this);
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void service(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();

        out.println("<html>");
        out.println("<head>");
        out.println("<title> TESTE </title>");
        out.println("</head>");
        out.println("<body>");
        out.println("Hello World!");
        out.println("</body>");
        out.println("</html>");
    }


}

PROBLEM: When I click on the submit button, it shows me the error:

**type Status report

message /Apontador_Web/LoginPage

description The requested resource is not available.**

And When I remove the tags "listener" and "context-param" it loads the servlet.

What can be happening?

4

2 回答 2

1

转到glashfish 服务器输出并查找一些异常

告诉我名字关闭异常

全部打印

于 2013-05-08T16:19:16.297 回答
0

您将需要在@WebServlet(urlPatterns={"/LoginPage"})您的班级名称上方添加,即public class LoginPage extends HttpServlet {

于 2013-11-16T09:25:03.943 回答