Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Output HTML in JSP

Posted on 2005-04-23
6
Medium Priority
?
2,333 Views
Last Modified: 2008-01-09
Hi,

It's been very long since i played with JSP,  so I'm very rusty.

I need to know,

1. How do I output html from JSP? Instead of using <%= can i use somthing else like out.println?

2. I have this code that uses out.println, but it won't work. I think it's because i can't use out.println that way. So, what is the other way that i can output HTML from a method in JSP? Is it something to do with PrintWriter?

My code,

<%!
      public void printNodes(List nodes) {
            
            List subList = null;
            
            for (int i = 0; i < nodes.size(); i++) {
                  
                  out.println(q(nodes.get(i).toString()) + ", " +  q(nodes.get(i+1).toString()) + ", " + q(nodes.get(i+2).toString()));

                  if (!nodes.get(i+3).equals("")) {
                        
                        out.println(",\n");
                        subList = nodes.subList(i+3, nodes.size());
                        printNodes(subList);
                        
                  }
                   out.println("]");
                  
                  if (i < (nodes.size() - 1)) {
                         out.println(",");
                         out.println("\n");
                  }
            }
      }
%>

When ran, i get "out cannot be resolved".


Melv.

P/S: Can someone point me to a good JSP tutorial page for me to brush up? Thanks
0
Comment
Question by:mwhc
  • 2
  • 2
  • 2
6 Comments
 
LVL 8

Expert Comment

by:koppcha
ID: 13850901
Hi

1> Instead of using <%= can i use somthing else like out.println?
        Yes you can if you want to put any data on to your JSP.
2>  Try using scrptlets(<% %>) instead of declaration(<%!  %>).Take the '!' off.

3>Reference for JSP http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/
 
0
 

Author Comment

by:mwhc
ID: 13850936
Hi,

Well, when i use out.println, i get "out cannot be resolved" error. I think it's because i put it in a method. I need to output html in my method. that's also why i use <%! instead of <%

1> Instead of using <%= can i use somthing else like out.println?
        Yes you can if you want to put any data on to your JSP.
2>  Try using scrptlets(<% %>) instead of declaration(<%!  %>).Take the '!' off.

3>Reference for JSP http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/
0
 
LVL 10

Expert Comment

by:makerp
ID: 13850949
use the built in response object

response.getWriter().print("my string with HTML etc");

to write output to the browser
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 10

Accepted Solution

by:
makerp earned 375 total points
ID: 13850956
without looking at the docs I dare say

PrintWriter out = response.getWriter();
out.print("ssssssssssss");

public void printNodes(List nodes,PrintWriter out) { ....

printNodes(nodes,response.getWriter());
0
 
LVL 8

Expert Comment

by:koppcha
ID: 13851127
Thinking this could help you even though you are done with the question ..This simple program works fine

<%!
      public void print(JspWriter out)throws IOException{
      out.println("I am in the method");
      }
      %>
     <%
      print(out);
     %>
0
 

Author Comment

by:mwhc
ID: 13851286
Thanks koppcha. Appreciate it. You have my salute!

Melv.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Dropbox has a relatively new feature called Smart Sync.  This feature allows Dropbox Professional (not plus) and Dropbox Business (if enabled) users to store information in Dropbox WITHOUT storing any files on their computer.
Often, the users face difficulty in accessing Outlook 2016 PST files on Windows 10 computer. One of the reasons behind it is the improper functioning of MS Outlook when the user tries to open it. MS Outlook suddenly stops working, or it will not op…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question