Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.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 在eclipse中不使用web.xml运行的Servlet_Java_Servlets - Fatal编程技术网

Java 在eclipse中不使用web.xml运行的Servlet

Java 在eclipse中不使用web.xml运行的Servlet,java,servlets,Java,Servlets,我可以在没有web.xml和@WebServlet(“/Myservlet”)的情况下在eclipse中运行动态web应用程序吗 在我的书中给出的示例中,我有三个html文件和一个servlet,但它没有在eclipse中运行。当我运行eclipse时,它给出一个错误:404sourcenotfound。我还注意到TrainingServlets(myprojectname)/部署描述符/servlets区域中没有显示servlet 它们的代码如下 **login.html** <!DOC

我可以在没有web.xml和@WebServlet(“/Myservlet”)的情况下在eclipse中运行动态web应用程序吗

在我的书中给出的示例中,我有三个html文件和一个servlet,但它没有在eclipse中运行。当我运行eclipse时,它给出一个错误:
404sourcenotfound
。我还注意到TrainingServlets(myprojectname)/部署描述符/servlets区域中没有显示servlet

它们的代码如下

**login.html**
<!DOCTYPE html>
<html>
<meta charset="ISO-8859-1">
<body>
<h2>Please provide login details</h2>
<form method="post" action="http://localhost/TrainingServlets/myservlet" name="myForm">
<br>User Id:
<input type="text" name="userid"/>
<br>Password:
<input type="password" name="pwd">
<br><br>
<input type="submit" value="Submit Form"/>
</form>

</body>
</html>


**welcome.html**
<!DOCTYPE html>
<html>
<meta charset="ISO-8859-1">
<body>
<h2>You have successfully logged in</h2>
</body>
</html>

**register.html**
<!DOCTYPE html>
<html>
<meta charset="ISO-8859-1">
<body>
<h2>Your login is incorrect.Please register yourself</h2>
<form method="post" action="" name="myform">
<br>Name:
<input type="text" name="userid"/>
<br> Address:
<input type="text" name="address"/>
<br> Phone No:
<input type="text" name="phoneno"/>
<br><br>
<input type="submit" value="Register"/>
</form>
</body>
</html>

**MyServlet**
package com;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class Myservlet extends HttpServlet{


    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
        processRequest(request,response);
    }
    protected void doPOST(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
        processRequest(request,response);
    }

    protected void processRequest(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
        String id = request.getParameter("userid");
        String pwd = request.getParameter("pwd");

        if (id.equals("ali")&& pwd.equals("vu")) {
            response.sendRedirect("welcome.html");
        }else{
            response.sendRedirect("register.html");
            response.sendError(response.SC_PROXY_AUTHENTICATION_REQUIRED,"Send Error Demo");
        }
    }

}
**login.html**
请提供登录详细信息

用户Id:
密码:

**欢迎光临** 您已成功登录 **register.html** 您的登录不正确。请自行注册
姓名:
地址:
电话号码:

**MyServlet** 包装组件; 导入java.io.*; 导入javax.servlet.*; 导入javax.servlet.http.*; 公共类Myservlet扩展了HttpServlet{ 私有静态最终长serialVersionUID=1L; 受保护的void doGet(HttpServletRequest请求,HttpServletResponse响应)抛出ServletException,IOException{ processRequest(请求、响应); } 受保护的void doPOST(HttpServletRequest请求、HttpServletResponse响应)引发ServletException、IOException{ processRequest(请求、响应); } 受保护的void processRequest(HttpServletRequest请求,HttpServletResponse响应)引发ServletException,IOException{ String id=request.getParameter(“userid”); 字符串pwd=request.getParameter(“pwd”); 如果(id.equals(“ali”)和pwd.equals(“vu”)){ sendRedirect(“welcome.html”); }否则{ sendRedirect(“register.html”); response.senderro(response.SC_PROXY_AUTHENTICATION_必需,“发送错误演示”); } } }
在servlet 3.0之前是不可能的。现在不需要web.xml

但如果您使用的是Servlet3.0之前的版本,那么它是必需的

然后Web.xml是部署描述符,它告诉服务器当前的servlet


简而言之,它是web应用程序的核心。没有它,您的应用程序就无法运行。

在servlet 3.0之前是不可能的。现在不需要web.xml

但如果您使用的是Servlet3.0之前的版本,那么它是必需的

然后Web.xml是部署描述符,它告诉服务器当前的servlet


简而言之,它是web应用程序的核心。没有它,您的应用程序就无法运行。

在servlet 3.0之前是不可能的。现在不需要web.xml

但如果您使用的是Servlet3.0之前的版本,那么它是必需的

然后Web.xml是部署描述符,它告诉服务器当前的servlet


简而言之,它是web应用程序的核心。没有它,您的应用程序就无法运行。

在servlet 3.0之前是不可能的。现在不需要web.xml

但如果您使用的是Servlet3.0之前的版本,那么它是必需的

然后Web.xml是部署描述符,它告诉服务器当前的servlet


简而言之,它是web应用程序的核心。没有它,应用程序就无法运行。

取决于“运行”的含义。您可以在servlet中放置一个main方法并以这种方式运行它,但是如果您想在servlet上执行HTTPRequest,则必须在web.xml中指定它或使用servlet注释。否则,服务器将无法将传入请求映射到该servlet。

取决于“运行”的含义。您可以在servlet中放置一个main方法并以这种方式运行它,但是如果您想在servlet上执行HTTPRequest,则必须在web.xml中指定它或使用servlet注释。否则,服务器将无法将传入请求映射到该servlet。

取决于“运行”的含义。您可以在servlet中放置一个main方法并以这种方式运行它,但是如果您想在servlet上执行HTTPRequest,则必须在web.xml中指定它或使用servlet注释。否则,服务器将无法将传入请求映射到该servlet。

取决于“运行”的含义。您可以在servlet中放置一个main方法并以这种方式运行它,但是如果您想在servlet上执行HTTPRequest,则必须在web.xml中指定它或使用servlet注释。否则,服务器将无法将传入请求映射到该servlet。

如果您的html文件位于根文件夹中(如果您使用的是eclipse的标准项目,请将html表单更改为:



另一方面,如果您使用的是Servlet 3.0(例如Tomcat 7),那么如果您使用以下注释,则可以避免使用文件
web.xml

@WebServlet(value=“/myservlet”,name=“myservlet”)
公共类Myservlet扩展了HttpServlet{…}
如果应用服务器支持Servlet3.0,则可以使用注释。更多信息请参阅

遵循JavaEE1.5概述的路径,Servlet规范3.0大量使用注释来声明Servlet、过滤器、侦听器和安全性。配置文件web.xml现在是可选的


如果您的html文件位于根文件夹中(在
WebContent
中,如果您使用的是eclipse的标准项目),请将html表单更改为:



另一方面,如果您使用的是Servlet 3.0(例如Tomcat 7),那么如果您使用以下注释,则可以避免使用文件
web.xml

@WebServlet(value=“/myservlet”,name=“myservlet”)
公共类Myservlet扩展了HttpServlet{…}
如果应用服务器支持Servlet3.0,则可以使用注释。更多信息请参阅

遵循JavaEE1.5概述的路径,Servlet规范3.0大量使用注释来声明Servlet、过滤器、侦听器和安全性。配置文件web.xml现在是可选的


如果html文件位于根文件夹中(在
WebContent
中),如果