我正在创建一个将在主页上显示<init-param>
值的网页。
我的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