• 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

Servlet to JSP using Tomcat 7 inside eclipse (JUNO)

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rooks Forgenal
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
reply
    Bookmark Topic Watch Topic
  • New Topic