Jsp ajax标签在jsp中不起作用..无法加载标记处理程序类异常

时间:2014-09-04 09:34:17

标签: ajax jsp servlets jboss ajaxtags

我是Ajax标签的新手。每当我尝试执行这些标记时,HTML部分就会按预期工作。但Ajax标签不起作用..

无法加载标记处理程序类异常“org.ajaxtags.tags.AjaxSelectTag”..

<%@ taglib uri="/WEB-INF/ajaxtld/ajaxtags.tld" prefix="ajax" %>

 <html>
   <head>
     <title>AJAX JSP Tag Library</title>



    <script type="text/javascript" src="js/prototype-1.6.0.3.js"></script>
    <script type="text/javascript" src="js/scriptaculous/scriptaculous.js"></script>
    <script type="text/javascript" src="js/overlibmws/overlibmws.js"></script>
    <script type="text/javascript" src="js/ajaxtags-1.2-beta1.js"></script>



    <link type="text/css" rel="stylesheet" href="/WEB-INF/css/ajaxtags.css" />
    <link type="text/css" rel="stylesheet" href="/WEB-INF/css/displaytag.css" />
</head>
<body>

    <form>



        Make:
        <select id = "make" name = "make">
            <option value="">Select make</option>
            <c:forEach items="${makes}" var="make">
                <option value="${make}">${make}</option>
            </c:forEach>
        </select>

        Model:
        <select id="model" name="model" >
            <option value="">Select model</option>
        </select>

        <input type="button" value="read">




        <div id="tar"></div>


    </form>

    <ajax:select baseUrl="$Sample/samplejava" source="make" target="model"   parameters="make={make}" />

</body>
</html>

servlet部分定义如下..

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class samplejava extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
        /* TODO output your page here. You may use following sample code. */
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet samplejava</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet samplejava at " + request.getContextPath() + "</h1>");
        out.println("Here is the response...");
        out.println("</body>");
        out.println("</html>");
    } finally {
        out.close();
    }
}

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);

    try {

        String res = request.getParameter("make");
        RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
        PrintWriter out = response.getWriter();
        out.println(res);
        response.getWriter().write("hai!! this is response...");
        response.sendRedirect("success.jsp");
    } catch (Exception e) {
        response.sendRedirect("error.jsp");
    }
}

@Override
public String getServletInfo() {
    return "Short description";
}// </editor-fold>

}

任何人都可以建议......

1 个答案:

答案 0 :(得分:0)

当我只是将doGet()方法更改为doPost()方法时,它的工作正常。

    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    public class samplejava extends HttpServlet {

    protected void processRequest(HttpServletRequest request, 
    HttpServletResponse response)throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
    /* TODO output your page here. You may use following sample code. */
    out.println("<!DOCTYPE html>");
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Servlet samplejava</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h1>Servlet samplejava at " + request.getContextPath() + "</h1>");
    out.println("Here is the response...");
    out.println("</body>");
    out.println("</html>");
   } finally {
    out.close();
   }
    }

   @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)//I just changed the doGet() to doPost(), its working fine
    throws ServletException, IOException {
      processRequest(request, response);

      try {

     String res = request.getParameter("make");
    RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
    PrintWriter out = response.getWriter();
    out.println(res);
    response.getWriter().write("hai!! this is response...");
    response.sendRedirect("success.jsp");
   } catch (Exception e) {
    response.sendRedirect("error.jsp");
   }
   }

    @Override
 public String getServletInfo() {
    return "Short description";
   }// </editor-fold>

      }