• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet to JSP using Tomcat 7 inside eclipse (JUNO)

 
Rooks Forgenal
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • 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:
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic