I am new to JSTL and JSPX technologies.
I am having a problem where when I use the c:choose, c:when, and c:otherwise tags to load things based on the servlet URL, it seems to ignore the conditionals and print everything. As a test, this what is in my jspx file
<?xml version="1.0" encoding="ISO-8859-1" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
<jsp:directive.page contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" session="true"/>
<jsp:output doctype-root-element="html"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-> transitional.dtd"
omit-xml-declaration="true" />
<html xmlns:c="http://java.sun.com/jsp/jstl/core">
<head>
<title>dummy application</title>
</head>
<body>
<c:choose>
<c:when test="${empty fixed}">
This is empty
</c:when>
<c:otherwise>
Dank Memes
</c:otherwise>
</c:choose>
</body>
</html>
</jsp:root>
My Servlet has the following code:
@WebServlet(urlPatterns = { "/Start", "/Start/*", "/StartUp", "/StartUp/*" })
public class Start extends HttpServlet {
private static final String FIXED = "fixed";
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Writer ro = response.getWriter();
String path = request.getRequestURI();
String last = path.substring(path.lastIndexOf('/') + 1);
System.out.println(last);
if(last.toString().contains("Fixed")) {
ro.append("This url contains Fixed \n");
request.setAttribute(FIXED, "blah");
// ro.append(getServletContext().getAttribute(FIXED).toString());
System.out.println("Contains fixed");
System.out.println("Value contained within the FIXED variable is " + getServletContext().getAttribute(FIXED));
}
else {
System.out.println("doesn't contain fixed");
System.out.println("Value contained within the FIXED variable is " + getServletContext().getAttribute(FIXED));
}
request.getRequestDispatcher(startPage).forward(request, response);
}
When you just pass in /Start into the url, it should print out "This is empty" and when you pass in /Start/Fixed, it should print out "Dank memes". However, when either urls are type in, what's printed out is "This is empty Dank memes". It seems to be completely skipping the choose tags alltogether. Any help in fixing this issue will be greatly appreciated.