New to JSP

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>
LVL 2
SaMuElAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sujithkumars123Commented:
Can you explain what you are expecting and how it is working for you....
0
CodingExpertsCommented:
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
somasekharCommented:
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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

SaMuElAuthor Commented:
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
somasekharCommented:
Can you please let me know your problem. so that i can try to solve your problem?

somasekhar
0
SaMuElAuthor Commented:
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
CodingExpertsCommented:
Hi Samuel

You can use a simple Taglib which can do this

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

-CE
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
somasekharCommented:
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
sunset1999Commented:
Why don't you just compromise and out.println("<h1>this is some text<h1>");

Will that work?  Haven't tried it myself.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.