• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with .jsp file on tomcat

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gurus please help,
I am testing my BGColor.jsp I am using tomcat standalone to test it. Test.html is retrieving BGColor.jsp.but the error is the BGcolor.jsp is with a background Green instead of yellow which I expected this is my first JSP program please tell me what is wrong.I am enclosing both the file codes.
Thank you in advance
kotamraju

*******test.html****************
html>
<head>
<title>Testing</title>
</head>
<body BGCOLOR = "yellow" >
<L1>current time: <%= new java.util.Date() %>
<a href="C:\jakarta-tomcat-3.2.3\webapps\ROOT\WEB-INF\classes\BGColor.jsp">bring it</a>
</body>
</html>
*********BGColor.jsp file*************
<html>
<head>
<title>Kotamraju's Home Page -- I Code Therefore I am!</title>
</head>
<% String bgColor=request.getParameter("bgColor");
boolean hasExplicitColor;
if(bgColor !=null) {
hasExplicitColor=true;
}else {
hasExplicitColor=false;
bgColor="white";
}
%>
<body BGCOLOR= "<%= bgColor %> " >
<%
if(hasExplicitColor) {
out.Println("you have explicit color of"+ bgColor):
}else
{out.println("no explicit so white is used");
}
%>
</body>
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You just have a few syntax errors in your code. Place both of these files in the same directory under your tomcat webapps directory.

test.html


test.jsp
 
kotamraju
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Alfonso Harding ,
I tried both of the codes and placed the files in webapp/root but strangely when i click bring it it is returning a page with black background and another thing is <a href="test.jsp?blue">bring it</a> what is ?blue
thank you
kotamraju
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In 'BGColor.jsp' you try to get get the parameter 'bgColor' out of the request:

therefore you also need to pass this parameter to the page from 'test.html' e.g. like this:

hope this helps
Rene
[ September 22, 2002: Message edited by: Rene Larsen ]
 
Alfonso Harding
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kotamraju,
I tested the code and it works fine for me. I'm using tomcat 4.0.4 but the version should not matter. Try restarting tomcat and try the page again.
The 'test.jsp?blue' is a url in the form of the query string. When you click on the link the value is passed in the form of a query string through from the URL and the line in
the test.jsp file:

takes the value after the question mark and passes it to the string variable bgColor and the rest of the code in the jsp file processes it from that point on.
The line:

is useful when you are passing data from a form element eg radio, textfield, etc)
 
kotamraju
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Alfonso Harding and Rene Larsen I have understood where I went wrong and I have made the changes I tested my code using both request.getQueryString();
request.getParameter("bgColor");
methods.
Kotamraju
 
reply
    Bookmark Topic Watch Topic
  • New Topic