Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

What part of this syntax do I have wrong?

Posted on 2009-07-14
6
Medium Priority
?
223 Views
Last Modified: 2012-05-07
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
<%
 
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);
%>
 
<% } %>
<% } %>

Open in new window

0
Comment
Question by:g118481
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 27

Accepted Solution

by:
mrcoffee365 earned 2000 total points
ID: 24856727
You need to tell us what the error is.

That said, I don't think the fragment you have posted will work the way you want.  And I assume it won't compile -- the fragment won't anyway.

You have a curly brace (})  on line 5 that probably shouldn't be there.  

If you remove that, then add an ending curly brace below line 30, then at least your code blocks are correct.

A Java IDE, or just a code editor with good syntax highlighting, would help you find problems like this one.  We have good luck with Eclipse, JEdit, Textpad, and the like.
0
 
LVL 6

Expert Comment

by:jwenting
ID: 24858165
Your first and biggest error is putting Java code inside  a JSP.
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.
0
 
LVL 27

Expert Comment

by:mrcoffee365
ID: 24859580
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 24925039
your topmost if condition is closing @ wrong place for the else part to work..
0
 
LVL 27

Expert Comment

by:mrcoffee365
ID: 24925640
Right -- as I said above, the curly brace at line 5 should be removed, and a closing brace added at line 30.
0
 
LVL 1

Author Closing Comment

by:g118481
ID: 31603413
thx
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
Are you an Exchange administrator employed with an organization? And, have you encountered a corrupt Exchange database due to which you are not able to open its EDB file. This article will explain all the steps to repair corrupt Exchange database.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question