Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP Display problem

 
Deepak Chawla
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I Have this JPS code, i am trying to disply filesnames with link on it but i am getting these 2 complier error
1. illegal start of expression
2. ')' expected
for(int i =0;i<filesdisplay;i++)
{

out.write(<a href="/docs/projectname/eventtype/book1.xls"> Book1.xls </a> ;

}
plz help
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Next time you post code click the button that says disable smiles. It will make it easir to figure out your code.
I know nothing about JSP but shouldn't it be

Eric
 
Deepak Chawla
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a project which has some docs and i am trying to display docs on JSP Page, for displaying docs i am using this code
for(int i =0;i<filesdisplay;i++)
{

out.write(<a href="/docs/projectname/eventtype/filenames[i]"> filenames[i] </a> ;
}
I get 2 errors
1.illegal start of expression
2. ')' expected
But if try to write the out statement like this below
out.write("<a href='/docs/projectname/eventtype/filenames[i]'> filenames[i] </a>");
i get output as filenames[i], instead of a filename eg a.doc, b.ppt.
 
Tim Baker
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think you need to reexamine your understanding of java syntax and grammar. what you want is this:

if you want to put a variable in a string you end that string ", use a concat operator + and then put the variable, then another concat + and you start a new string "
 
dee kal
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am not sure how far this will work...just give it a try...
out.write("<a href='/docs/projectname/eventtype/filenames[i]'>" +
filenames[i] + "</a>");
Bye.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dees code is not going to work.... since it does not take the array into account for the url string.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64692
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using out.write to emit HTML? That's inside out.
You should be using JSP to include Java in your HTML, not HTML in your Java.
bear
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic