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

ajax访问servlet没反应

ajax访问servlet没反应

我爱静静0 2016-07-09 19:16:30
 <script type="text/javascript" src="WEB-INF/lib/jquery-1.8.3.js"></script>  <script type="text/javascript">  function bb(){      $.get("aja");                          }  </script>  </head>  <a href="javascript:bb()">aa</a>  <a href="aj">bb</a>  <body>      </body>servlet中:package servlet;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;@WebServlet (urlPatterns={"/aja"})public class aj extends HttpServlet {    /**     * The doGet method of the servlet. <br>     *     * This method is called when a form has its tag value method equals to get.     *      * @param request the request send by the client to the server     * @param response the response send by the server to the client     * @throws ServletException if an error occurred     * @throws IOException if an error occurred     */    public void doGet(HttpServletRequest request, HttpServletResponse response)            throws ServletException, IOException {        response.setContentType("text/html");        PrintWriter out = response.getWriter();        out.print("false");        out.flush();        out.close();    }    /**     * The doPost method of the servlet. <br>     *     * This method is called when a form has its tag value method equals to post.     *      * @param request the request send by the client to the server     * @param response the response send by the server to the client     * @throws ServletException if an error occurred     * @throws IOException if an error occurred     */    public void doPost(HttpServletRequest request, HttpServletResponse response)            throws ServletException, IOException {        doGet(request, response);    }}
查看完整描述

2 回答

已采纳
?
HansonQ

TA贡献223条经验 获得超56个赞

a标签 写到body 标签里面

查看完整回答
1 反对 回复 2016-07-09
?
我爱静静0

TA贡献1条经验 获得超0个赞

放在里面了还是不行啊

查看完整回答
反对 回复 2016-07-10
  • HansonQ
    HansonQ
    $.get("aja");这个地方有问题 . 在js里面 先 var basePath = <%=request.getContextPath()%> ; 然后var rquestPath=basePath+"/"+"aja" 然后换成:$.get(rquestPath);
  • HansonQ
    HansonQ
    $.ajax({ type: "GET", url: "test.js", dataType: "script" }); 在看看是不是你的ajax 写的有问题
  • 2 回答
  • 0 关注
  • 2740 浏览

添加回答

举报

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