This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes IDEs, Version Control and other tools and the fly likes Servlet to JSP using Tomcat 7 inside eclipse (JUNO) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Servlet to JSP using Tomcat 7 inside eclipse (JUNO)" Watch "Servlet to JSP using Tomcat 7 inside eclipse (JUNO)" New topic
Author

Servlet to JSP using Tomcat 7 inside eclipse (JUNO)

Rooks Forgenal
Ranch Hand

Joined: Jun 05, 2009
Posts: 82
Let me begin by saying I am VERY new to servlets. I only just got my system setup to develop locally. I am able now to run everything (including Tomcat 7) inside eclipse. I have made my first servlet and jsp. I have a button in my JSP that will one day post a string, "HelloWorld" to a servlet. Until then, I am just making a String[2][5] out of Hello \n World, then I send it to my JSP. It is here I run into a problem. I don't want to cast my 2d array as a String object type in the JSP.

My Question: How do I preserve the object type in the transition from servlet to jsp?

Although I don't think it will help, I will provide my code.

EDIT: I have edited this code so it is at least working.
SERVLET:

JSP:
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5838
    
    7

I recommend you do not use server-side script (the stuff inside the <% ... %>) in your JSPs. Your servlet is passing a object to the JSP, so use tag libraries and the expression language to extract the information out of the object. In your example, the twoDStrArr object is a little complex for me to come up with a decent example off the top of my head, so let me change your example to something very simple to show what I mean.

In your servlet, do this:

Then in the JSP do:

If you look at the docs for the standard taglib you will see <c:foreach> tag which lets you iterate over arrays and collection. Here is a good tutotial:
http://docs.oracle.com/javaee/5/tutorial/doc/bnakc.html

JBoss In Action
Rooks Forgenal
Ranch Hand

Joined: Jun 05, 2009
Posts: 82
As suggested by Peter Johnson, the solution to my issue is to use JSTL 1.2. The code is below. Thank you for your help.
SERVLET:JSP:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet to JSP using Tomcat 7 inside eclipse (JUNO)