user2641353
user2641353

Reputation: 15

How to access to element from another class

I have servlet where i need to show list of products first image next title and price.

i try with

    Proizvodi pr = new Proizvodi();
 for(int i=0; i<pr.getKatalog().size();i++)
            {
              out.println("<br />");
              out.print("<img src='pr.getKatalog().get(i).getImg()'>");
              out.print("<p>pr.getKatalog().get(i).getTitle()</p> ");
              out.print("<p>pr.getKatalog().get(i).getPrice()</p> ");
            }

but it doesn't work. I hope that u can help me.

Upvotes: 0

Views: 50

Answers (2)

iCrus
iCrus

Reputation: 1248

Regarding the newline issue you mentioned, remove the <p> and </p> tags from all of the out.print() statements and it should be in all one line then.

Upvotes: 0

Juned Ahsan
Juned Ahsan

Reputation: 68725

You need to replace this:

          out.print("<img src='pr.getKatalog().get(i).getImg()'>");

with

          out.print("<img src='" + pr.getKatalog().get(i).getImg() + "'>");

to get the method return value appended to the string. Otherwise pr.getKatalog().get(i).getImg() being in double quotes will be treated as a normal string and not as a method call.

You need to do the same thing for these statements as well:

   out.print("<p>pr.getKatalog().get(i).getTitle()</p> ");
   out.print("<p>pr.getKatalog().get(i).getPrice()</p> ");

Upvotes: 2

Related Questions