日期:2014-05-17 浏览次数:20589 次
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>