兔橘长啊 2019-11-20 17:45 采纳率: 0%
浏览 4685

配置web.xml后显示HTTP Status 404 – 未找到

实现通过表单向servlet中传送数据,配置webxml后一直显示HHTP404,但我把添加的配置内容删掉后反而可以运行了

web.xml配置:

<servlet>
    <servlet-name>ComputeBill</servlet-name>
    <servlet-class>myservlet.ComputeBill</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>ComputeBill</servlet-name>
    <url-pattern>/ComputeBill</url-pattern>
</servlet-mapping>

图片说明

图片说明

jsp代码:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>利用表单给servlet传送数据</title>
</head>
<body>
<form action="ComputeBill"  method="post">
输入账单:<br>
<textarea name='billMess' rows="5" cols="30">
</textarea>
<br>
<input type=submit value="提交">
</form>
</body>
</html>

servlet代码(省略导包):


public class ComputeBill extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public ComputeBill() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see Servlet#init(ServletConfig)
     */
    public void init(ServletConfig config) throws ServletException {
        // TODO Auto-generated method stub
        super.init(config);
    }

    /**
     * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
     */
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        //1、设置编码格式
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        //2、利用printwriter类输出流声明out对象,利用response对象调用getwriter方法获取一个输出流,利用out对象调用print方法
        PrintWriter out=response.getWriter();
        out.print("<html><body bgcolor=yellow>");
        //3、通过request对象获取表单中文本区的内容送给str
        String str=request.getParameter("billMess");
        if(str==null||str.length()==0)
            return;
        String [] price=str.split("[^0123456789.]+");
        double sum=0;
        try
        {
            for(int i=0;i<price.length;i++)
            {
                if(price[i].length()>=1)
                    sum+=Double.parseDouble(price[i]);
            }
        }
        catch(NumberFormatException e){out.print(e);}
        out.print(str+"<br>的消费额:"+sum+"元");
        out.print("</body></html>");


    }
  • 写回答

1条回答 默认 最新

  • 毕小宝 博客专家认证 2019-11-20 18:10
    关注

    可能是你添加的 Servlet 类没有成功发布到项目中,导致项目找不到 Servlet 。

    评论

报告相同问题?

悬赏问题

  • ¥15 luckysheet
  • ¥25 关于##爬虫##的问题,如何解决?:
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题