Here is a Servlet for processing
import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class CreateTip extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request,response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //虚拟一个商品列表 String[][] shop ={{"商品一","90","photo/photo1.jpg"}, {"商品二","190","photo/photo2.jpg"}, {"商品三","290","photo/photo3.jpg"} }; //获得客户端提交的参数 int index =Integer.parseInt(request.getParameter("index")); response.setContentType("text/xml"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); //以XML文档形式返回给客户端 out.println("<shop>"); out.println("<name>"+shop[index][0]+"</name>"); out.println("<price>"+shop[index][1]+"</price>"); out.println("<photo>"+shop[index][2]+"</photo>"); out.println("</shop>"); out.flush(); out.close(); }}
<body> <h2>工具提示</h2><br> <hr> <a href="#" onmouseover="over(0)" onmouseout="out()">商品一</a><br><br> <a href="#" onmouseover="over(1)" onmouseout="out()">商品二</a><br><br> <a href="#" onmouseover="over(2)" onmouseout="out()">商品三</a><br><br> <div id="tip" style="position:absolute;display:none;border:1px;border-style:solid;"> <TABLE id="tipTable" border="0" bgcolor="#ffffee"> <TR align="center"> <TD><img id="photo" src="" height="80" width="80"></TD> </TR> <TR> <TD></TD> </TR> <TR> <TD></TD> </TR> </TABLE> </div> </body>
If relative doesn’t work, use absolute.
This is the full path of my image resource, which is in the root directory of the project
D:JavaworkspaceTestAJAXphotoWrite down the address of the image you linked and take a look. Also pay attention to the image format.
//Virtual product list
String[][] shop ={{"Product One","90","photo/photo1.jpg"},
{"Product Two" ,"190","photo/photo2.jpg"},
The addresses are all written in the Servlet. Then call it back and change the following src
to the one above, right?
Write the address of the image you linked to and take a look. Also pay attention to the image format