我正在尝试使用 tomcat 服务器版本 9 运行 java 应用程序。当我创建第一个项目并且项目运行成功但问题是当我创建另一个项目并将该项目分配给服务器时,我收到以下错误。服务器 Tomcat v9.0 本地主机上的服务器无法启动。这是index.html的代码<!DOCTYPE html><html><body><body><form action="login">User Name:<input type="text" name="userName"/>Password:<input type="password" name="userPassword"/><input type="submit" value="submit"/></form></body></html>这是 Servlet 代码。package Edureka;import java.io.*;import javax.servlet.annotation.WebServlet;import javax.servlet.http.*;@WebServlet("/login")public class MyServlet1 extends HttpServlet{/** * */ private static final long serialVersionUID = 1L;public void doGet(HttpServletRequest request, HttpServletResponse response) {try{response.setContentType("text/html");PrintWriter pwriter = response.getWriter();String name = request.getParameter("userName");String password = request.getParameter("userPassword");pwriter.print("Hello here:"+name);pwriter.print(" Your Password is: "+password);//Creating two cookiesCookie c1=new Cookie("userName",name);Cookie c2=new Cookie("userPassword",password);//Adding the cookies to response headerresponse.addCookie(c1);response.addCookie(c2);pwriter.print("<a href='welcomehere'>View Details</a>");pwriter.close();}catch(Exception exp){System.out.println(exp);}}}这是 web.xml 文件。<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0"> <display-name>Cookies</display-name> <servlet><servlet-name>Servlet1</servlet-name><servlet-class>Edureka.MyServlet1</servlet-class></servlet>这是我尝试在 Eclipse 中运行它时的屏幕截图。
添加回答
举报
0/150
提交
取消