实例化servlet类时出错
这是我的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>"); }}
每当我部署我的战争文件并点击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(Unknown Source)
我哪里错了?
如果使用web.xml
定义servlet,那么删除@WebServlet
注释,因为现在您有2个不同的映射。