码迷,mamicode.com
首页 > 编程语言 > 详细

JavaWeb项目中的Servlet

时间:2019-11-22 00:56:42      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:func   注解   提示   访问   att   存在   val   -name   ESS   

1.创建Servlet

2.在jsp中用ajax调用

$.post("<%=request.getContextPath()%>/AjaxValidationServlet",{"userName":userName},function(message){
     alert(message);       
});

这是异步验证用户是否存在。

问题:报404,提示没有这个servlet。

解决:

  1.在web.xml中引用的xsi:若是3.0.xsd之后,的有注解可以解决

@WebServlet(name = "AjaxValidationServlet",urlPatterns = "/AjaxValidationServlet")

  2.在3.0之前的需要在web.xml中配置servlet名和映射

  <servlet>
        <servlet-name>AjaxValidationServlet</servlet-name>
        <servlet-class>com.web.AjaxValidationServlet</servlet-class>
    </servlet>
  <servlet-mapping>
        <servlet-name>AjaxValidationServlet</servlet-name>
        <url-pattern>/AjaxValidationServlet</url-pattern>
    </servlet-mapping>

这样就可以正常访问了。

JavaWeb项目中的Servlet

标签:func   注解   提示   访问   att   存在   val   -name   ESS   

原文地址:https://www.cnblogs.com/Choleen/p/11909160.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!