[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

New to JSP

Posted on 2004-11-23
9
Medium Priority
?
196 Views
Last Modified: 2010-04-01
How do I embed html in a function without resorting to using out?

Why doesn't this do what I expect?


<%@ page import="java.util.Date"%>
<html>
<body>
<%@ include file="present.html"%>
<%!
      void testFunction(){
            for (int i=0; i<5; i++){
                  %>
                  This is just some basic text!
                  <%!
            }
      }
%>
<Table border=1>
<%
      testFunction();
      for (java.util.Enumeration e=System.getProperties().propertyNames();e.hasMoreElements();){
            %>
            <%=System.getProperty((String)e.nextElement())%>
            <br>
            <%
      }            

      testFunction();
%>
      <jsp:include page="present.html"/>
<% testFunction();%>
</table>
</body>
</html>
0
Comment
Question by:SaMuEl
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 2

Expert Comment

by:sujithkumars123
ID: 12662470
Can you explain what you are expecting and how it is working for you....
0
 
LVL 6

Expert Comment

by:CodingExperts
ID: 12662743
If you need to print anything on the browser u need to write out.println("...');

say

out.println(System.getProperty((String)e.nextElement()));

-CE
0
 
LVL 2

Expert Comment

by:somasekhar
ID: 12662784
Hello try this



<%@ page import="java.util.Date"%>
<html>
<body>
<%@ include file="present.html"%>
<%!
    public String testFunction(){
          for (int i=0; i<5; i++){
             
              return("This is just some basic text!");
             
          }
     }
%>
<Table border=1>
<%= testFunction();%>
<%
     for (java.util.Enumeration e=System.getProperties().propertyNames();e.hasMoreElements();){
          %>
          <%=System.getProperty((String)e.nextElement())%>
          <br>
          <%
     }          
%><%=testFunction();%>
     <jsp:include page="present.html"/>
<%=testFunction();%>
</table>
</body>
</html>


hope this help

somasekhar
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Author Comment

by:SaMuEl
ID: 12663536
Ah yes somasekhar I thought of that, but what I really want to do is be able to write freely in html inside a method.
Insteading of having to use escape characters etc...
It would also be nice to be able to use the include directive inside a function like that also.
0
 
LVL 2

Expert Comment

by:somasekhar
ID: 12664388
Can you please let me know your problem. so that i can try to solve your problem?

somasekhar
0
 
LVL 2

Author Comment

by:SaMuEl
ID: 12670162
Well that's just it, I'm new to JSP and want to know how to drop back into html if it's possible, in a method.
<%
     for (java.util.Enumeration e=System.getProperties().propertyNames();e.hasMoreElements();){
          %>
          <%=System.getProperty((String)e.nextElement())%>
          <br>
          <%
     }
%>      
Using html inside a for loop works fine in the actual code, but I want it to be done in a method.

To be precise I want to know if it's possible to drop back to html in a method instead of using out.print("");.

example
<%!
    void myMethod() {%>
       <h1>"My html code"</h1>
   <%!}
%>

instead of...
<%!
     void myMethod(){
         out.print("<h1>\"My Html Statements\"</h1>");
     }
%>
0
 
LVL 6

Accepted Solution

by:
CodingExperts earned 200 total points
ID: 12671836
Hi Samuel

You can use a simple Taglib which can do this

http://www.servletsuite.com/servlets/fortag.htm

-CE
0
 
LVL 2

Expert Comment

by:somasekhar
ID: 12672221
Hey samuel

The answer for your statement is ..

It is not possible.

You have to return it as string or some java object and to be printed at respective page.


regards
somasekhar
0
 

Expert Comment

by:sunset1999
ID: 12806102
Why don't you just compromise and out.println("<h1>this is some text<h1>");

Will that work?  Haven't tried it myself.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In the below post we have mentioned the best hosting type for startups. Also, check out some of the superlative web hosting companies that are proposing affordable web hosting solutions to host your startup website.
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Screencast - Getting to Know the Pipeline
Suggested Courses

873 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