0

<init-param>ホームページに値 を表示する Web ページを作成していました。

DDはこのように見えます:

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    web-app_2_4.xsd"
    version="2.4">

    <servlet>
        <servlet-name>CheckIt</servlet-name>
        </servlet-class>servlet.Test</servlet-class>

        <init-param>
            <param-name>param1</param-name>
            <param-value>LikeICare</param-value>

            <param-name>param2</param-name>
            <param-value>AgainLikeICare</param-value>
        </init-param>

    </servlet>

    <servlet-mapping>
        <servlet-name>CheckIt</servlet-name>
        <url-pattern>/home</url-pattern>
    </servlet-mapping>
</web-app>  

私のコードはservlet.Test次のようになります。

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class Test extends HttpServlet{
    public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException{
        String param1 = getServletConfig().getInitParameter("param1");
        String param2 = getServletConfig().getInitParameter("param2");

        response.setContentType("text/html");
        PrintWriter writer = response.getWriter();
        writer.println(param1 + "<br>" + param2);

    }
}  

ホームページはここにあります:

<html>
    <body>
        <h1> Init Parameters  will be displayed here</h1>
    </body>
</html>  

は次のdeployment environmentようになります。
ここに画像の説明を入力

ただし、ブラウザに URL を次のように入力すると、404 エラーが発生しますhttp://localhost:8080/checkInit/home.html

何がうまくいかなかったのか教えてください

classesフォルダは次のような適切な構造を持っていますservlet/Test.java

4

1 に答える 1

0

Try accessing like http://localhost:8080/checkInit/home You are appending .html at the end in your URL: http://localhost:8080/checkInit/home.html

In your DD you have configured the servlet to be invoked as /home

<servlet-mapping>
  <servlet-name>CheckIt</servlet-name>
  <url-pattern>/home</url-pattern>
</servlet-mapping>
于 2013-02-08T17:11:01.990 に答える