gpt4 book ai didi

java - 实例化 Servlet 类时出错

转载 作者:行者123 更新时间:2023-12-01 12:19:47 24 4
gpt4 key购买 nike

这是我的index.html

<form action="submitForm" method="get">
<input type="submit" name="Submit" value="submit" onclick="" />
</form>

这是我的 web.xml

`<servlet>
<servlet-name>submitForm</servlet-name>
<servlet-class>student.StudentSurveyFormSubmit</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>submitForm</servlet-name>
<url-pattern>/submitForm</url-pattern>
</servlet-mapping>`

还有我的 servlet 类

package student;
@WebServlet("/StudentSurveyFormSubmit")
public class StudentSurveyFormSubmit extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<h1>" + "Hi, "+request.getParameter("firstName") +" I am here" + "</h1>");
}}

每当我部署 war 文件并单击 sumbot 按钮时,都会出现异常:

服务器遇到内部错误 (),导致其无法完成此请求。

异常

javax.servlet.ServletException:实例化 servlet 类 Student.StudentSurveyFormSubmit 时出错 org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) java.lang.Thread.run(来源不明)

我哪里出错了?

最佳答案

如果您使用 web.xml 定义 servlet,则删除 @WebServlet 注释,因为现在您有 2 个不同的映射。

关于java - 实例化 Servlet 类时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26769641/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com