【问题标题】:Trying to open a simple JSP file produces HTTP Status 500尝试打开一个简单的 JSP 文件会产生 HTTP 状态 500
【发布时间】:2012-07-02 06:09:41
【问题描述】:

在我之前的帖子here 之后,我已将所有源文件删除到一个名为model 的包中,现在项目在执行http://localhost:8080/MyFirstServlet 时拒绝加载。

我怀疑罪魁祸首是web.xml,这是文件:

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>MyFirstServlet</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

  <servlet>
   <description></description>
   <display-name>LoginServlet</display-name>
   <servlet-name>LoginServlet</servlet-name>
   <servlet-class>model.LoginServlet</servlet-class>
 </servlet>


  <servlet-mapping>
    <servlet-name>LoginServlet</servlet-name>
    <url-pattern>/model/LoginServlet</url-pattern>
  </servlet-mapping>
</web-app>

  [1]: https://stackoverflow.com/questions/11282231/jsp-page-wont-move-the-another-page-after-user-enters-the-input/11283006#11283006

这是 index.jsp:

<%@ page language="java" contentType="text/html; charset=windows-1255"
    pageEncoding="windows-1255"%>
<!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=windows-1255">
<title>Insert title here</title>
</head>
<body>
<form action="model/LoginServlet" method="POST">
        First Name: <input type="text" name="firstName" size="20"><br>
        Last Name: <input type="text" name="lastName" size="20">
        <br><br>
        <input type="submit" value="Submit">
</form> 

</body>
</html>

这是项目的层次结构:

当我执行http://localhost:8080/MyFirstServlet 并到达这里时:

我在文本字段中输入firstsecond,然后得到这个:

我已经尝试修复它但没有任何效果,所以我很感激任何建议,谢谢:)

【问题讨论】:

    标签: java mysql jsp servlets jdbc


    【解决方案1】:

    你的表单动作应该是

    <form action="model/LoginServlet" />
    

    并且您的登录 servlet 应该正确定义包。

    package model;
    

    您的 web.xml 还必须通过完全限定名称声明此 servlet 类

    model.LoginServlet
    

    您的 servlet 必须扩展 HttpServlet。

    如果您确保上述所有内容都正确到位,但仍然无法正常工作。然后,您可能需要在 Eclipse 中检查此项目的构建路径设置。

    【讨论】:

      【解决方案2】:
      <servlet>
         <description></description>
         <display-name>LoginServlet</display-name>
         <servlet-name>LoginServlet</servlet-name>
         <servlet-class>model.LoginServlet</servlet-class>
       </servlet>
      

      您错过了 servlet 类的包。

      【讨论】:

      • 如果这仍然不起作用,你应该有一个新的不同的堆栈跟踪。否则你的新 web.xml 没有正确部署,它仍然引用旧的。
      【解决方案3】:

      stacktrace 清楚地显示了错误是什么,ClassNotFoundException 表示 servlet Container 无法在 web.xml 中找到指定的 Class。

      【讨论】:

      • 我可以看到,但我该如何解决?
      • 请清理您的 Servlet,删除警告/不必要的引用包,然后尝试通过停止 tomcat 重新部署所有内容,然后部署然后启动服务器。如果您仍然不工作,请告诉我。
      【解决方案4】:

      LoginServlet.java 中的第一行代码应该是

      package model;
      

      【讨论】:

      • 请尝试使用 action="/model/LoginServlet" 而不是 action="model/LoginServlet"
      猜你喜欢
      • 2013-01-25
      • 1970-01-01
      • 1970-01-01
      • 2017-06-07
      • 1970-01-01
      • 2014-04-22
      相关资源
      最近更新 更多