网站无法显示页面。(eclipse neon 3 Tomcat 9)

Posted

技术标签:

【中文标题】网站无法显示页面。(eclipse neon 3 Tomcat 9)【英文标题】:The website cannot display the page.(eclipse neon 3 Tomcat 9) 【发布时间】:2021-08-08 23:42:52 【问题描述】:

这是 Add.jsp 文件

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Add</title>
</head>
<body>

<form method="post" action="AddServlet">
No1:<input type="text" value="no1"/><br><br>
No2:<input type="text" value="no2"/><br><br>

<input type="submit" name="add" value="Add Numbers"/>
</form>
</body>
</html>

当我尝试在 Eclipse neon、Tomcat 版本 9 上运行 servlet 应用程序时出现错误 500,我现在很困惑,我检查了我的文件很多次,但它仍然是一样的!!我在我的任何文件中也没有发现任何编程错误!!现在好迷茫!!

错误描述:服务器遇到了一个意外情况,导致它无法完成请求。

我在我的代码中找不到任何问题,我不明白为什么。我的代码所做的是,从 Add.jsp 文件中获取两个数字并将它们显示在 Results.jsp 文件中。

这是我的小服务程序

package servlet;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/AddServlet")
public class AddServlet extends HttpServlet 
    private static final long serialVersionUID = 1L;
       

    public AddServlet() 
        super();
 
    


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
        
        response.getWriter().append("Served at: ").append(request.getContextPath());
    


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 

        
        int no1=Integer.parseInt(request.getParameter("no1"));
        int no2=Integer.parseInt(request.getParameter("no2"));
        
        int total=no1+no2;
        
        RequestDispatcher dispatcher=getServletContext().getRequestDispatcher("/Results.jsp");
        
        request.setAttribute("Sum", total);
        dispatcher.forward(request,response);
        
    

This is the screenshot of the error page

【问题讨论】:

同时显示 add.jsp 页面。 您好,感谢您的回复,我再次编辑了线程。现在可以看到 add.jsp 文件了 【参考方案1】:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Add</title>
</head>
<body>

<form action="AddServlet" method="post" >
    No1:<input type="text" name="no1"/><br><br>
    No2:<input type="text" name="no2"/><br><br>

    <input type="submit" name="add" value="Add Numbers"/>
</form>
</body>
</html>

//it was the fault in the form,where it should be name="num1" not 'value' keyword, I have used the wrong keyword, after changing the the keyword value to the name the problem fixed

//I'm a beginner I've forgot Jsp a little now it's fine

/*
my error was:

Type Exception Report

Message null

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception
java.lang.NumberFormatException: null
    java.lang.Integer.parseInt(Unknown Source)
    java.lang.Integer.parseInt(Unknown Source)
    servlet.AddServlet.doPost(AddServlet.java:32)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:652)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)


Note The full stack trace of the root cause is available in the server logs.
*/ 

//I hope this will be useful for anyone! have a great day!

【讨论】:

以上是关于网站无法显示页面。(eclipse neon 3 Tomcat 9)的主要内容,如果未能解决你的问题,请参考以下文章

Eclipse neon“无法创建JVM”

Eclipse Neon无法启动

Eclipse Juno 和 Neon 中的错误 - 无法再次打开控制台视图

无法在eclipse neon 1中安装公制插件

如何在 Eclipse Neon 中启用 C++11 语法?

Eclipse Neon.2 无法识别 Android ADT