Reputation: 21893
I've got a servlet that puts something in request but I can't call it with jstl. What am i doing wrong?
<%@ page import="beans.Patient"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri='http://java.sun.com/jstl/fmt' prefix='fmt' %>
<jsp:useBean id="patBean" class="beans.Patient" scope="session"/>
<c:set var="patientName" value="${patient.name}"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
test
<form action="PatientAction" method="post">
<input type="text" name="patientId" id="patientId"></input>
<input type="submit"/>
</form>
<c:out value="${patientName}" />
<c:out value="${patBean.name}" />
Upvotes: 1
Views: 2772
Reputation: 403551
You don't need to bother with <useBean>
when you're using JSTL, just refer to the bean directly. So if your servlet put a Patient
into the session, you can get its name using:
<c:out value="${patient.name}" />
Upvotes: 4
Reputation: 597234
request attributes are accessible via the name they have been put in . If you have had request.setAttribute("foo", fooValue)
then it is accessible via ${foo}
. This is true if you are within the same request. This means the servlet has to do a forward rather than a redirect. If a redirect happens, that's a new request, and the old values are lost.
Upvotes: 1