Hello Friends, Plz help me to figure out what my problem is?(jsp code) thanks =)
in my JSP page, I created a cell whose image source I want to get from servlet. I put the link tag to ask servlet for imgSrc, but it does not work . Please show me how to change the imgSrc in JSP page using servlet. I want the JSP to merely show the result, not a dispatch to another page. here is my code : Zbody> <form action="testServlet.java"> <TABLE border="0" align="center"> <TR height="40"> <TD width="40"><a href="Hoda/testServlet?direction=b"><img src=<%=request.getAttribute("imgSrc")%> width="40" height="40" /></a></TD> </form> </body> SERVLET: @WebServlet("/testServlet") public class testServlet extends HttpServlet { String imgSrc = "red.png"; protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IO hoda_mahmoodi: HttpServletResponse response) throws ServletException, IOException { String str = request.getParameter("direction"); if (str.startsWith("b")) { imgSrc = "black.png"; } request.setAttribute("imgSrc", imgSrc); } }
Join our real-time social learning platform and learn together with your friends!