Why are ALL the jsp Java expressions evaluated to empty values if not all contain null/empty values? The expressions ARE evaluated, but not to the correct values.
This was working at some point, then I had to do some other changes and only now I noticed that the expressions are not working anymore. I tried to revert my other changes, to bring the code to a a minimum as shown below, but it's still not working. Any idea what I'm doing wrong/missing below? I'm running the webapp in Tomcat 8.5.
This is what's in index.jsp:
<%@ page isELIgnored="false" %>
<%@ page import="com.aif.User" %>
<html>
<head>
</head>
<%
User user = new User();
String emptyString = "";
String nonEmptyString = "NonEmptyStringValue";
%>
<body>
Java scriptlet with null value: '<%=user.getName()%>' <br /><br />
Java expression with null value: '${user.getName()}' should display '' <br /><br />
Java expression with empty value: '${emptyString}' should display '' <br /><br />
Java expression with non-empty non-null value: '${nonEmptyString}' should display 'NonEmptyStringValue' <br /><br />
</body>
</html>
The above evaluates to this in the browser:
Java scriptlet with null value: 'null'
Java expression with null value: '' should display ''
Java expression with empty value: '' should display ''
Java expression with non-empty non-null value: '' should display 'NonEmptyStringValue'
What's in User.java
package com.aif;
public class User {
private String name;
public String getName() {
return name;
}
}
What's in web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
</web-app>
What's in pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.aif</groupId>
<artifactId>xyz2</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
</project>
?? – Ankush G Jul 21 '17 at 13:28