This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP values not being generated  RSS feed

 
Simon Ingram
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,
I am currently inching my way through Beginning JSP 2.0 from Wrox, a book that introduces JSP to punters like myself working alone and without a clue and relying on the book to explain things. So, I have done my form in Pizza.html on a standalone PC. The submit button is attached to a file called Process.jsp which is sitting in the same directory as the html page, namely:
c:\Tomcat 5.0\webapps\Pizza
and directory Pizza contains the usual WEB-INF subdirectory with �classes� and �lib� below that. The Process.jsp file contains a simple table containing the name value pairs from the form. i.e.
<td>Name</td>
<td>${param.Name}</td>
Tomcat is installed and working OK, but when I type:
http://localhost:8080/Pizza/Pizza.html
and press the button, the output gives me a table with:
Name ${param.Name}
Instead of:
Name Richmal Compton
i.e. the JSP is not being resolved and sent back. The book does not seem to anticipate failure and offers no advice. Can anyone help?
Regards and thanks,
Simon
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you are talking about the new EL in JSP 2.0. What got me a few weeks back was the fact that there is a new DTD for the web.xml file to actually use the JSP 2.0 specs.

Try that and see if that helps. If not, let me know...
 
Simon Ingram
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right Greg, I am talking about the Expression Language in JSP 2.0 but not about any of its new features. My problem is with the very basic features! A JSP should evaluate the expressions and return a result. The param collection simply contains the data entered into a form by the client, so the expression
$ {param.Name}
should contain the the Name entered into the text element called Name on my html form. But it does not. The JSP simply displays the expression. I suspect my problem is a very basic set up issue, but having checked everything I can think of, I am no nearer to getting the JSP page to work!
regards
Simon
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your information in the firs tpost is correct, it's probably because you have called your file "Pizza.html" rather than "Pizza.jsp". By default most servlet/JSP containers are set up to only process files ending with ".jsp" as Java Server Pages. HTML files are sent direct to the browser, as you seem to be observing.
Could it be as simple as that?
 
Simon Ingram
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was a nice try, Frank but it didn't make any difference. I am completely baffled by this and I can't make any progress.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, then I think we need some more information. Could you please provide us with your web.xml file and your complete Pizza.jsp. Maybe we can better tell with some more stuff to look at.
 
Simon Ingram
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg, thanks for agreeing to look at this: I have a file called Pizza.html
<body>
<form action="Process.jsp" method="post">
<h1>Welcome to Simon's on-line Pizza Emporium!<br />Fill out the form below to place your order!</h1>
<h2>Your Information:</h2>
<p>Name:<p/>
<input type="text" name="Name" size="30"></p>
<p>
<input type="submit" value="Place Order" />
<input type="reset" value="Reset" />
</p>
</form>
</body></html>
and the corresponding Process.jsp:
<html>
<head>
<title></title>
<style type="text/css">
</style>
</head><body>
<h2>Pizza Order Confirmation</h2>
<p>Please ensure this data is correct</p>
<table border="1">
<tr>
<td>Name:</td>
<td>${param.Name}</td>
</tr>
</table>
</body>
</html>
I don't know what the web.xml file is! My book has not mentioned it so far. Perhaps this is the problem?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to make sure that the file is being translated, start with some simple JSP experssions (not EL). Something like <%= 3+4 %> perhaps.
Standard debugging techniques: start simple to isolate the problem at the most fundamental level.
bear
[ January 05, 2004: Message edited by: Bear Bibeault ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what the web.xml file is! My book has not mentioned it so far. Perhaps this is the problem?
Ahaa! I bet this is the problem. Since you are only using JSP pages, you really don't NEED a web.xml file. The problem however is kind of what I stated in my first post. For some reason, TOMCAT won't evaluate EL without knowing that you want to. The way Tomcat realizes this is via the web.xml file. There are 2 options.
1. There is an init param I believe that you can place in the web.xml file in a so that Tomcat 5 will know you want to evaluate expressions. This way the web.xml file is backwards compatible. (I need to find where I read this)
2. Adjust the DTD declarative in your web.xml file so that Tomcat 5 knows you are using the features of J2EE 1.4.
I have no idea why Tomcat works this way. And I am not even 100% sure I am correct. But if you can try this, then you can verify whether it is true or not.
So what you need to do is create a directory structure like the following

Now, put this exact code in your web.xml file and try the program again and let me know what happens.

Now run your code and see what happens. I am curious to know why Tomcat requires this in version 5. It could be because 5 is not final yet. I use Resin for my server and it just uses J2EE 1.4 no matter what. It doesn't care about the web.xml file unless you need it for Servlet purposes.
 
Simon Ingram
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gregg,
I am assuming from your directory diagram that you want the web.xml file in the WEB-INF folder and the Pizza.html and Process.jsp in the folder above i.e in directory Pizza, like so:
c:\webapps\Pizza\WEB-INF
I have now rerun by putting
http://localhost:8080/Pizza/Pizza.html and alas, the same result!
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it works just fine as is in Resin. So I would say it is a Tomcat issue because it doesn't work in Tomcat for me. If someone wants to move this to the Tomcat forum, it might find better results??
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I tried it on Tomcat 5 with the web.xml file and it worked just fine. Tomcat NEEDS that web.xml file to work with EL because without it, it didn't work for me either. But with it, it worked like a champ. If you want, send me an Email to ethought@embeddedthought.com and I will send you a war file of your application in the correct directory structure.
I would say that there is an issue with your book as well as an issue with Tomcat.
 
Simon Ingram
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just tried Bear's suggestion and the simple expression doesn't evaluate either:
<td>Name:</td>
<td>Try<%= 2+3 %></td>
just gives me:
Name: Try
so it looks like an even more fundemental problem. Nothing evaluates! I have checked the installation repeatedly. Tomcat starts and runs. The directory structure seems OK. The SDK has been running OK for months. What can it be?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So Simon, make any progress with this?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are the Tomcat examples working?
 
Simon Ingram
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope, when I execute them the tables contain unresolved values. i.e. Basic Arithmetic
EL Expression Result
\${1+2} ${1+2}
Must be a set up issue, but I have no idea what more to check.
 
Simon Ingram
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My apologies, the examples are working OK. It's just my Pizza form and JSP that don't work.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!