所以,问题是-我是这个JSP servlet的新手,在这里输入代码,然后使用IDE Netbeans
我的Web应用程序是关于-
“从用户那里获取两个数字,然后必须通过提供结果通过打开新Web来执行提交按钮”结果-是48
那我为什么要经历另一个Web选项卡中找不到的错误404
我正在IDE NETBEANS中使用最新版本的服务器TOMCAT 每一个安装程序,仍然会通过此错误404找不到在Web上安装
WEB.XML-
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>pra</servlet-name>
<servlet-class>worthwrite.workplease</servlet-class>
</servlet>
<servletmapping>
<servlet-name>pra</servlet-name>
<url-pattern>/heyy</url-pattern>
</servletmapping>
</web-app>
THIS IS servlet java code-
package worthwrite;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author hp
*/
public class workplease {
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
int i=Interger.parseInt(request.getParameter("no1"));
int j=Interger.parseInt(request.getParameter("no2"));
int k=i+j;
out.println("additon is ="+k);
}}}
THIS IS JSP CODE JUST CHANGED BY INDEX.HTML TO JSP-
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="heyy">
Enter a number<input type="Text" name="no1"><br>
Enter a number2<input type="Text" name="no2">
<input type="submit">
<h1>Hello World!</h1>
</body>
</html>
期望的结果必须是- 输入一个数字 输入一个数字 (提交按钮)
新的Web标记打开并显示结果 例如:RESULT IS 24
实际输出-
第一个Web浏览器随输出打开 输入一个数字 输入一个数字 (提交)
第二次- 显示- 状态404未找到 strong文本