这是我的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(未知来源)
我哪里错了?
答案 0 :(得分:1)
如果使用web.xml
定义servlet,则删除@WebServlet
注释,因为现在有2个不同的映射。