Solved

What part of this syntax do I have wrong?

Posted on 2009-07-14
6
213 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
6 Comments
 
LVL 26

Accepted Solution

by:
mrcoffee365 earned 500 total points
Comment Utility
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
Comment Utility
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 26

Expert Comment

by:mrcoffee365
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
Comment Utility
your topmost if condition is closing @ wrong place for the else part to work..
0
 
LVL 26

Expert Comment

by:mrcoffee365
Comment Utility
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
Comment Utility
thx
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Marketing can be an uncomfortable undertaking, especially if your material is technology based. Luckily, we’ve compiled some simple and (relatively) painless tips to put an end to your trepidation and start your path to success.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now