Java 当代码来自AJAX时,网站功能会中断

Java 当代码来自AJAX时,网站功能会中断,java,html,css,ajax,Java,Html,Css,Ajax,我有一个图像库,当我将鼠标悬停在任何图像上时,图像会缩回显示一些文本 当我在HTML文档中有以下HTML代码(在文章的底部)时,一切正常 然而,当我将完全相同的HTML代码放在Javaservlet中并将其返回到页面时,一切看起来都正常,但图像回调不再起作用 你知道为什么会这样吗?也许我需要做一些刷新,使它正常工作 库中某个项目的相关代码: <li> <div class="header"><p><a href="product

我有一个图像库,当我将鼠标悬停在任何图像上时,图像会缩回显示一些文本

当我在HTML文档中有以下HTML代码(在文章的底部)时,一切正常

然而,当我将完全相同的HTML代码放在Javaservlet中并将其返回到页面时,一切看起来都正常,但图像回调不再起作用

你知道为什么会这样吗?也许我需要做一些刷新,使它正常工作

库中某个项目的相关代码:

  <li>
           <div class="header"><p><a href="product.jsp">Product 1 Shirt</a></p></div>
           <div class="gallery_item">
                    <img src="gallery/thumb/gallery_01.jpg" width="214" height="194" class="cover" alt="" />                        
                    <p>Highlight 1</p>
                    <p>Highlight 2</p>
                    <p>Highlight 3</p>
                    <a href="product.jsp" class="btn alignleft" title="More Info">More Info</a>                                               
                    <a href="gallery/fullsize/gallery_01.jpg" class="zoom" data-rel="prettyPhoto[gallery1]">Enlarge</a>                                                                    
                    <a href="gallery/fullsize/gallery_02.jpg" data-rel="prettyPhoto[gallery1]"></a>
           </div>
           <div class="p2"><p>Price: $10</p></div>
           <div class="p2"><p>In Stock: Yes</p></div>              

    </li>
  • 亮点1

    亮点2

    亮点3

    价格:$10

    库存:是

  • 根据请求:servlet:

      public void service(HttpServletRequest request,
            HttpServletResponse response) throws IOException,
            ServletException
    {
        PrintWriter out = response.getWriter();
        response.setContentType("text/html");
        String requestType = request.getParameter("type");
        String result;
    
        if(requestType.equals("getproductlist"))
        {
            Products products = Products.getProductsInstance();
            String keywords = request.getParameter(("keywords"));
            String organization = request.getParameter(("organization"));
            String price = request.getParameter(("price"));
            String sort = request.getParameter(("sort"));
    
            result = products.getProducts(keywords, organization, price, sort);
    
    //this next lines of html are actually what is returned from products.getProducts. I'm just putting it here for clarity. All the variables (name, h1, etc) are okay.
    
            result += "<li>"
                        + "<div class=\"header\"><p><a href=\"product.jsp\">"+ name +"</a></p></div>"
                        + "<div class=\"gallery_item\">"
                        + "<img src=\"gallery/thumb/gallery_01.jpg\" width=\"214\" height=\"194\" class=\"cover\" alt=\"\" />"
                        + "<p>"+ h1 +"</p>"
                        + "<p>"+ h2 +"</p>"
                        + "<p>"+ h3 +"</p>"
                        + "<a href=\"product.jsp\" class=\"btn alignleft\" title=\"More Info\">More Info</a>"
                        + "<a href=\"gallery/fullsize/gallery_01.jpg\" class=\"zoom\" data-rel=\"prettyPhoto[gallery1]\">Enlarge</a> "
                        + "<a href=\"gallery/fullsize/gallery_02.jpg\" data-rel=\"prettyPhoto[gallery1]\"></a>"
                        + "</div>"
                        + "<div class=\"p2\"><p>Price: "+ itemPrice +"</p></div>"
                        + "<div class=\"p2\"><p>In Stock: "+ inStock +"</p></div>   "
                        + "</li>";
    
    
            out.println(result);
            out.close();
    
        }
    
    公共作废服务(HttpServletRequest),
    HttpServletResponse响应)引发IOException,
    ServletException
    {
    PrintWriter out=response.getWriter();
    response.setContentType(“text/html”);
    字符串requestType=request.getParameter(“类型”);
    字符串结果;
    if(requestType.equals(“getproductlist”))
    {
    Products=Products.getProductsInstance();
    字符串关键字=request.getParameter((“关键字”);
    字符串organization=request.getParameter((“组织”);
    字符串price=request.getParameter((“price”);
    String sort=request.getParameter((“sort”);
    结果=products.getProducts(关键字、组织、价格、排序);
    //接下来的几行html实际上是从products.getProducts返回的内容。为了清楚起见,我把它放在这里。所有变量(名称、h1等)都可以。
    结果+=“
  • ” +“

    ” + "" + "" +“”+h1+“

    ” +“”+h2+“

    ” +“”+h3+“

    ” + "" + " " + "" + "" +价格:“+itemPrice+”

    ” +库存:“+inStock+”

    ” +“
  • ”; out.println(结果); out.close(); }
    发布servlet版本没有发布JavaScript。我还建议使用根相对路径(与servlet上下文一起)而不是完全相对的,这样到资源处理程序的映射可以从顶部更清晰。发布java servlet/action类谢谢到目前为止。更新。如果需要更多信息,请告诉我哪里是不起作用的
    javascript
    代码?