Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 呈现一个特定URI的html文件,然后在Tomcat8.0中出现错误_Java_Html_Tomcat_Servlets - Fatal编程技术网

Java 呈现一个特定URI的html文件,然后在Tomcat8.0中出现错误

Java 呈现一个特定URI的html文件,然后在Tomcat8.0中出现错误,java,html,tomcat,servlets,Java,Html,Tomcat,Servlets,在java文件中没有指定URI的html文件呈现,然后正确运行 当html文件通过IF块以特定URI呈现时,它会给出错误 但若我通过PrintWriter对象发送消息,那个么在if块中,它可以正常工作 错误 *HTTP Status 500 - Servlet execution threw an exception type Exception report message Servlet execution threw an exception description The ser

在java文件中没有指定URI的html文件呈现,然后正确运行

当html文件通过IF块以特定URI呈现时,它会给出错误

但若我通过PrintWriter对象发送消息,那个么在if块中,它可以正常工作

错误

    *HTTP Status 500 - Servlet execution threw an exception
type Exception report
message Servlet execution threw an exception
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet execution threw an exception
    com.javaHello.App.doGet(App.java:22)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    com.javaHello.App.doGet(App.java:22)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    com.javaHello.App.doGet(App.java:22)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    com.javaHello.App.doGet(App.java:22)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    com.javaHello.App.doGet(App.java:22)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    com.javaHello.App.doGet(App.java:22)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    com.javaHello.App.doGet(App.java:22)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    com.javaHello.App.doGet(App.java:22)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    com.javaHello.App.doGet(App.java:22)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)*
App.java

 public class App extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        String Url= String.valueOf(req.getRequestURI());
        RequestDispatcher rd=req.getRequestDispatcher("docs/myPage.html");
        System.out.println(Url);
        if (Url.equals("/service/reg")){
            rd.include(req, res);
        }else {
            rd.include(req, res);
            System.out.println("server is hit");
        }
    }
}
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>MyServlet</servlet-name>
        <servlet-class>com.javaHello.App</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>MyServlet</servlet-name>
        <url-pattern>/service/*</url-pattern>
    </servlet-mapping>


</web-app>
    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>static Page</title>
</head>
<body>
<h2>Registration  Page</h2>

<form method="get" action="/register">
    <table>
        <tableBody>
            <tr>
                <td>UserName : </td>
                <td><input type="text" name="UserName"></td>
            </tr>
            <tr>
                <td>Password : </td>
                <td><input type="password" name="Password"></td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td><input type="submit" value="register" name="btnReg"></td>
                <td><input type="reset" value="clear" name="btnClr"></td>
            </tr>
        </tableBody>
    </table>
</form>

</body>
</html>

MyServlet
com.javaHello.App
MyServlet
/服务/*
myPage.html

<?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>MyServlet</servlet-name>
        <servlet-class>com.javaHello.App</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>MyServlet</servlet-name>
        <url-pattern>/service/*</url-pattern>
    </servlet-mapping>


</web-app>
    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>static Page</title>
</head>
<body>
<h2>Registration  Page</h2>

<form method="get" action="/register">
    <table>
        <tableBody>
            <tr>
                <td>UserName : </td>
                <td><input type="text" name="UserName"></td>
            </tr>
            <tr>
                <td>Password : </td>
                <td><input type="password" name="Password"></td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td><input type="submit" value="register" name="btnReg"></td>
                <td><input type="reset" value="clear" name="btnClr"></td>
            </tr>
        </tableBody>
    </table>
</form>

</body>
</html>

静态页面
注册页
用户名:
密码:
项目结构


尝试更改rd.include(请求、回复);向rd转发(请求、回复);如果使用转发(req、res);同样的错误也发生了#Anand Rockzz请显示您的项目文件夹结构好吗..看起来像其他一些外部配置问题,您能试着运行我编写的示例吗-