简体   繁体   中英

how to forward the particular image clicked value to a servlet

// My Jsp Code

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
</head>
<body>
<h1>Welcome to Loader</h1>
<c:forEach var="sampleMap" items="${MAP}">
<center><a href="brand1.jsp">
<img src="<%=request.getContextPath()%>/logo/${sampleMap.value}"></a>
<c:set var="brand" value="${sampleMap.value}" scope="session"/>
</center>
</c:forEach>
</body>
</html>

Using Servlet I am fetching the image from the database and storing in the map ,Fetching in the jsp using for:each and putting in the a href tag so tat i will we work like an image button ..

But My problem is I want to send the image corresponding value to the Servlet when a particular image get clicked and

<c:set var="brand" value="${sampleMap.value}" scope="session"/>

This above code is always sending the last fetched value ..

Plzz Help

You can do it by putting the value in the url of the href as a parameter:

<a href="brand1.jsp?image=${sampleMap.value}">

Then in the servlet:

request.getParameter("image");
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
</head>
<body>
<h1>Welcome to Loader</h1>
<c:forEach var="sampleMap" items="${MAP}">
<center><a href="brand1.jsp?imagevalue=${sampleMap.value}">
<img src="<%=request.getContextPath()%>/logo/${sampleMap.value}"></a>
</center>
</c:forEach>
</body>
</html>

and use request.getParameter("iamgeValue"); in your servlet

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM