Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / January 2006

Tip: Looking for answers? Try searching our database.

JSP script riddled with errors - can't resolve them - please help

Thread view: 
phillip.s.powell@gmail.com - 16 Jan 2006 20:11 GMT
I do not possess the ability to translate PHP into JSP, but I thought I
could.

Here is the code:

[CODE]
<%@
  page import="ppowell.*,
               java.io.*,
               java.net.*,
               java.util.*,
               java.util.regex.*,
               javax.servlet.http.*,
               ppowell.java_string_tools"
%>

<%@ page session="true" %>

<%!

/*--------------------------------------------------------------------------
     File: CHAT_MESSAGES.JSP
     Created By: Phil Powell
     Creation Date: 3/13/2004
     Modified Date: 1/17/2006
     Purpose: Retrieve messages via servlet and display
     Dependencies: NONE
     Cookies: ChatGlobals.CHAT_COOKIE_NAME
     Sessions: NONE
     Structure: Standalone script to be placed in ./includes directory

---------------------------------------------------------------------------*/

 HttpSession session = request.getSession(true);
 String cookie = "", content = "", errorMsg = "";
 HTMLRetriever retriever = null;

%>
<html>
<%

 Cookie[] cookieArray = request.getCookies();
 for (int i = 0; i < cookieArray.length; i++) {
  if
(cookieArray[i].getName().trim().toLowerCase().equals(ChatGlobals.CHAT_COOKIE_NAME.trim().toLowerCase())
&&
      cookieArray[i].getValue().length() > 0
     ) { // DISPLAY CHATROOM
   cookie = cookieArray[i].getValue();

%>
<head>

<script type="text/javascript">
<!--
 // IF THIS IS IE THEN YOU HAVE TO DO A HASH PROPERTY SET TO GET TO
'view'
 var ie = (document.all &&
navigator.appName.toLowerCase().indexOf("konqueror") == -1) ? true :
false;
 if (ie) window.location.hash = 'view';

 // FOR IE && OPERA USERS - USE META REFRESH
 if (ie || window.opera)
  document.writeln("<meta http-equiv=\"Refresh\" content=\"5;URL=<%=
request.getHeader("script-uri") %>\">");

//-->
</script>

<%

/*-----------------------------------------------------------------------------------------
    If the user is using Konqueror only the <meta> Refresh tag will
appear and no Javascript
    except for what is above (which is tailored also against
Konqueror).  If they are using
    any other browser then the sequence of <script> and <noscript>
will appear undisturbed.
    This is to ensure that Konqueror users will have their screens
refreshed.

-------------------------------------------------------------------------------------------*/
 Pattern konqPattern = Pattern.compile("konqueror");
 Matcher konqMatcher =
konqPattern.matcher(request.getHeader("User-Agent"));

 if (konqMatcher.matches()) {
  // DISPLAY <noscript> FOR EVERYONE ELSE
%>
<noscript>
<%
 }
%>

<!-- WILL RESET IN 5 SECONDS FOR HTML -->
<meta http-equiv="Refresh" content="5;URL=<%=
request.getHeader("script-uri") %><%

 if (konqMatcher.matches()) out.println("?junk=" .
java_string_tools.randstring(16));

%>#view">

<%
  // USE THIS TO DETECT IF USER AGENT INDICATES THE BROWSER IS
KONQUEROR - IF SO, HARD-DISPLAY THE META REFRESH TAG
 if (!konqMatcher.matches()) {
  // DISPLAY <noscript> FOR EVERYONE ELSE
%>

</noscript>

<!-- I SAW THIS SCRIPT IN
http://grizzlyweb.com/webmaster/javascripts/refresh.asp -->

<script language="javascript1.0" type="text/javascript">
<!--
function getPage() {
 // THIS OPERA/KONQUEROR HANDLER I SAW IN
http://www.brothercake.com/scripts/resize.php
 if (!ie && !window.opera &&
navigator.appName.toLowerCase().indexOf("konqueror") == -1)
  window.location.href = url;
}
//-->
</script>

<script language="javascript1.1" type="text/javascript">
<!--
function getPage() {
 if (!ie && !window.opera &&
navigator.appName.toLowerCase().indexOf("konqueror") == -1)
  window.location.replace(url);
}
//-->
</script>

<script language="javascript1.2" type="text/javascript">
<!--
 function getPage() {
  if (!ie && !window.opera &&
navigator.appName.toLowerCase().indexOf("konqueror") == -1)
   window.location.reload(false); // DYNAMIC CONTENT TO REFRESH PER
CALL
 }
//-->
</script>

<script type="text/javascript'>
<!--

 var url = '<%= request.getHeader("script-uri") %>#view';

 if (!ie && !window.opera &&
navigator.appName.toLowerCase().indexOf("konqueror") == -1)
  timer = window.setTimeout("getPage()", 5000); // REFRESH EVERY 5
SECONDS

//-->
</script>
<%
 } // END OF SCRIPT BLOCK - NO SCRIPT APPEARS IN KONQUEROR BUT DOES IN
EVERYTHING ELSE
%>

<style type="text/css">
<!--
TD {
font: 900 15px "Arial Narrow", Arial;
}
-->
</style>
</head>
<body background="<%= ChatGlobals.HOME_DOMAIN %>/images/bg.jpg"
bgcolor="#000000" text="#cccccc" link="#cc0000" vlink="#cc0000"
alink="#cccccc">
<font face="Arial Narrow, Arial" size="-2" color="#cccccc">
<%

  if (errorMsg.length() > 0) out.println(errorMsg);

  try {    // MUST PLACE WITHIN try{} BLOCK DUE TO REQUIREMENTS FOR NEW
2-PARAMETER java.net.URLEncoder METHOD encode()
   retriever = new HTMLRetriever(ChatGlobals.SERVLET_SELF +
"/ppowell.ChatServlet?message=" +
                                 URLEncoder.encode("/m", "UTF-8") +
"&nickname=" +
                                 URLEncoder.encode(cookie, "UTF-8")
                                );
  } catch (UnsupportedEncodingException uee) {
   errorMsg += "Cannot send message: " + uee.toString();
  } catch (Exception e) {
   errorMsg += "Unknown error: " + e.toString();
  }
  content = retriever.getHTML();

  // DETERMINE IF CONTENT IS RECEIVED, ELSE, RETRIEVE FROM SESSION
  if (content != null && !content.equals("")) {
   if (content != null) {
    Pattern p = Pattern.compile("(<td)(>[\\s\\t]*)(" + cookie +
")(>.*</td>.*)");
    Matcher m = p.matcher(content);
    content = m.replaceAll("$1 style=\"color:#ffffcc\"$2$3$4");
   }
   out.println(content);

/*-------------------------------------------------------------------------------------
       New 1/17/2006: JSP version: replace "$content" with "content"
    New 4/6/2004: Preserve each value of $content into a session variable
to ensure
    that if there is a disconnect with the servlet the cached content will
display to
    the user instead, not noticing much of a difference

--------------------------------------------------------------------------------------*/
   session.setAttribute("msg_content", (Object)content);
  } else {
   out.println(session.getAttribute("msg_content").toString());
  }

%>
</font>
<!-- VIEWER WILL GO HERE -->
<a name="view"></a>
</body>
<%
   break;
  } // END OF ALL COOKIE-BASED HTML INCLUSION
 }
%>
</html>
[/CODE]

And here are the errors:

[ERROR]
500 Servlet Exception
/~ppowell/includes/chat_messages.jsp:26: cannot find symbol
symbol  : variable request
location: class __27eppowell._includes._chat_0messages__jsp
 HttpSession session = request.getSession(true);
                       ^
/~ppowell/includes/chat_messages.jsp:78: cannot find symbol
symbol  : variable java_string_tools
location: class java.lang.String
 if (konqMatcher.matches()) out.println("?junk=" .
java_string_tools.randstring(16));
                                        ^
Note:
/usr/local/resin2/work/__27eppowell/_includes/_chat_0messages__jsp.java
uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors

[/ERROR]

I'm sorry to dump at once, but it's easier than to point out one at a
time and multi-post them.

Help!

Phil
James Westby - 17 Jan 2006 00:04 GMT
> I do not possess the ability to translate PHP into JSP, but I thought I
> could.
[quoted text clipped - 259 lines]
>
> Phil

Hi,

You can't just post a huge piece of code like this and expect someone to
code up what you want. For one it's not clear what you are trying to do
or where your problems lie. For another that code is way too ungainly to
look at. If you want someone to take it seriously then you need to clean
it up before you post. Start by taking out all the unecessary stuff like
all the javascript, it's completely irrelevant. Next take out all the
dependecies on your own code, especially if your not going to provide
it. Take out the imports for a start. Then strip the code down to the
bare minimum that will exhibit the problem that you are experiencing.
You never know, this processes might help you see what is going on.

As for the errors you reported,

the first is because you have put the declaration inside a <%! %> block,
and request is not understood there. I can give you my best guess why if
you want, but if you're not a java coder then it might not be clear to
you. To solve the problem only reference request from <% %> tags.

As for the second problem I have no idea what you are trying to do, what
is the java_string_tools variable? Where are you expecting it to come from?

As I said, if you want more help post something that people can deal
with and you will receive help. Explain what you are trying to do, how
you are trying to it, and why you think that method should work. And
keep posting the exact error messages, they will help you also.

James
phillip.s.powell@gmail.com - 17 Jan 2006 07:35 GMT
Sorry but I got tired of posting 5 - 6 questions a day on 2 scripts
that confuse me.

As far as declarations are concerned, in PHP we don't often do
declarations except for "static" or "global", so the concept is pretty
much foreign to us, so I couldn't figure that one out and your
explaining it would sadly go over my head, so I'll just take your word
for it and do it, thus it worked now, thanx!

Phil

> > I do not possess the ability to translate PHP into JSP, but I thought I
> > could.
[quoted text clipped - 289 lines]
>
> James
Alan Krueger - 17 Jan 2006 13:43 GMT
> Sorry but I got tired of posting 5 - 6 questions a day on 2 scripts
> that confuse me.

Maybe spending those days studying JSP tutorials would sever you better,
then?
phillip.s.powell@gmail.com - 17 Jan 2006 14:23 GMT
There's a linguistic irony in what you just said.  I'll leave that to
you to figure out.

Phil

> > Sorry but I got tired of posting 5 - 6 questions a day on 2 scripts
> > that confuse me.
>
> Maybe spending those days studying JSP tutorials would sever you better,
> then?
Alan Krueger - 17 Jan 2006 17:51 GMT
> There's a linguistic irony in what you just said.  I'll leave that to
> you to figure out.

Actually, it's known as a "typographical error", colloquially known as a
"typo".
James Westby - 17 Jan 2006 00:07 GMT
> I do not possess the ability to translate PHP into JSP, but I thought I
> could.
[quoted text clipped - 259 lines]
>
> Phil

Sorry, I forgot to ask, why are you using the statement

HttpSession session = request.getSession(true);

?

As you included

<%@ page session="true" %>

then you already have a appropriately typed variable named session that
will be bound to an existing session if there is one, or a new one if
not. I assume that is the behaviour that you are after.

James
Noodles Jefferson - 17 Jan 2006 00:09 GMT
In article <1137442278.056007.70550@g49g2000cwa.googlegroups.com>,
phillip.s.powell@gmail.com took the hamburger, threw it on the grill,
and I said "Oh wow"...

> I do not possess the ability to translate PHP into JSP, but I thought I
> could.
[quoted text clipped - 258 lines]
>
> Phil

You should be having a servlet do the majority of the processing. .jsp's
more for the presentation aspect of it. Some people will tell you not to
use java code at all with jsp's but I think that's too strict. But I do
agree that the amount of code should be minimized whenever possible.

________            __________           __________
|        | <------- |          | <------ |  base    |
| jsp    | -------->| servlet  |-------> |classes & |
|________|          |__________|         |_data_____|

This is simplistic and there are other ways of doing something like this
which may be more appropriate to what you're trying to accomplish.

Signature

Noodles Jefferson
mhm31x9 Smeeter#29 WSD#30
sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM

NP: "Informer" -- Snow

"Our earth is degenerate in these latter days, bribery and corruption
are common, children no longer obey their parents and the end of the
world is evidently approaching."
--Assyrian clay tablet 2800 B.C.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.