HTML中调用servlet的问题(?)

最近在学习servlet。刚开始时,按照案例一行一行的敲代码。不过,出问题了。

hello1.html

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="UTF-8">
 5     </head>
 6     <body style="font-size:24px">
 7         <form action="hello1" method="get">
 8             Name:<input name="name"><br />
 9             Content Me:<br />
10             QQ<input type="checkbox" name="contact" value="qq" />
11             Tel<input type="checkbox" name="contact" value="tel" />
12             WeChat<input type="checkbox" name="contact" value="wechat" />
13             <br />
14             <input type="submit" value="OK" />
15         </form>
16     </body>
17 </html>

web.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3     xmlns="http://xmlns.jcp.org/xml/ns/javaee"
 4     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
 5     http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
 6     id="WebApp_ID" version="3.1">
 7     <servlet>
 8         <servlet-name>hello1Servlet</servlet-name>
 9         <servlet-class>unitTwo.Hello1Servlet</servlet-class>
10     </servlet>
11     <servlet-mapping>
12         <servlet-name>hello1Servlet</servlet-name>
13         <url-pattern>/hello1</url-pattern>
14     </servlet-mapping>
15 </web-app>

Hello1Servlet.java

 1 package unitTwo;
 2 
 3 import java.io.IOException;
 4 import java.io.PrintWriter;
 5 
 6 import javax.servlet.ServletException;
 7 import javax.servlet.http.HttpServlet;
 8 import javax.servlet.http.HttpServletRequest;
 9 import javax.servlet.http.HttpServletResponse;
10 
11 public class Hello1Servlet extends HttpServlet {
12     /**
13      * 
14      */
15     private static final long serialVersionUID = 1L;
16 
17     protected void service(HttpServletRequest request, HttpServletResponse response)
18             throws ServletException, IOException {
19         PrintWriter out = response.getWriter();
20         String name = request.getParameter("name");
21         out.println("<h1>Hello, " + name + "</h1>");
22         String[] contacts = request.getParameterValues("contact");
23         if (contacts != null) {
24             out.print("<h1>Contact Information: </h1>");
25             for (String info : contacts) {
26                 out.print("<h1>" + info + "</h1>");
27             }
28         }
29         out.close();
30     }
31 }

运行在TOMCAT v8.0上,结果是,在Eclipse EE上运行时,正常显示,但是到了浏览器上,就出问题了,显示为未找到该网页,应该是错误404。

至于原因,首先归结于在Eclipse EE上服务开启受到了限制,然后关了Eclipse EE,用命令重启服务,结果还是错误。

纠结了一天了,决定先将问题写下来,待深入些再来解决。

或者希望有大神能降临,轻轻松松的将这个问题秒杀。

以上

转载于:https://www.cnblogs.com/SummerinShire/p/4631163.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值