出现404报错
package com.imooc.servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; public class CalculateServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String num1 = request.getParameter("num1"); String num2 = request.getParameter("num2"); PrintWriter out = response.getWriter(); out.println("<h1>Addition Calculator:</h1><br/>"); out.println("<h1>Calculation result:"+(Integer.parseInt(num1)+Integer.parseInt(num2))+"</h1>"); } }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>加法计算器</title> </head> <body> <form action="/calculate"> 加数1:<input type="text" name="num1" style="margin:15px 0"/><br/> 加数2:<input type="text" name="num2" style="margin:15px 0"/><br/> <button type="submit">计算</button><br/> </form> </body> </html>
<servlet> <servlet-name>calculate</servlet-name> <servlet-class>com.imooc.servlet.CalculateServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>calculate</servlet-name> <url-pattern>/calculate</url-pattern> </servlet-mapping>
问题描述:
想知道如何解决404错误
22
收起
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星