为了账号安全,请及时绑定邮箱和手机立即绑定

Ajax连接servlet连接问题 ajax无法访问servlet?

Ajax连接servlet连接问题 ajax无法访问servlet?

黑色嘉年华ALEX 2016-10-15 18:27:45
前端HTML<body>    <button id="getvalue">    请点击    </button>    <div id = "value"></div>  </body>Ajax代码$("#getvalue").click(function(){ $.ajax({ url:"/servlet/doajax", cache:true, type:"GET", data:{username:"admin"}, async:false, datatype:"html", error:function(request){ alert("cuowu"); }, success:function(data){ $("#value").html(data); } }); });servlet代码public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); String username = request.getParameter("username"); System.out.println(username); PrintWriter out = response.getWriter(); out.print("welcome "+username); out.flush(); out.close(); }xml配置 <servlet>    <description>This is the description of my J2EE component</description>    <display-name>This is the display name of my J2EE component</display-name>    <servlet-name>doajax</servlet-name>    <servlet-class>servlet.doajax</servlet-class>  </servlet>  <servlet-mapping>    <servlet-name>doajax</servlet-name>    <url-pattern>/servlet/doajax</url-pattern>  </servlet-mapping>
查看完整描述

1 回答

?
__YXQ__

TA贡献48条经验 获得超15个赞

ajax请求里的url应该是doajax

查看完整回答
反对 回复 2016-10-16
  • 1 回答
  • 0 关注
  • 2760 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信