g118481
asked on
What part of this syntax do I have wrong?
I have an error somewhere in this JSP code.
Any idea how to fix it?
I think I am missing some tags.
I have comments in the code to say what it is trying to do.
Thanks
Any idea how to fix it?
I think I am missing some tags.
I have comments in the code to say what it is trying to do.
Thanks
<%
if (db2username == null) {
// variable from http server does not exist
}
%>
<%-- redirect the user to the login page --%>
<meta http-equiv="refresh" content="0; url=http://myUrl.com?app=CD">
<% } else { %>
<%-- if the variable is passed from the login page, then check if the cookie exist --%>
<%
Cookie[] cookies = request.getCookies();
for (int i=0; i<cookies.length; i++)
{
if (cookies[i].getName().equals("db2username"))
{
%>
<% } else { %>
<%-- if the cookie does not exist, then create it --%>
<% Cookie rdb2username = new Cookie("db2username",db2username);
rdb2username.setMaxAge(2592000);
response.addCookie(rdb2username);
%>
<% } %>
<% } %>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It is not an error to have Java code in a JSP page. There are some development frameworks which recommend what jwenting has said above. There are others which don't.
your topmost if condition is closing @ wrong place for the else part to work..
Right -- as I said above, the curly brace at line 5 should be removed, and a closing brace added at line 30.
ASKER
thx
That's maintained for legacy/backwards compatibility reasons only. You should only ever use JSTL/EL in a JSP, and do whatever Java code you require in a servlet that afterwards forwards to that JSP for rendering.