Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8378147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:51:38+00:00 2026-06-09T15:51:38+00:00

Should be direct HTML printing in a JSP declaration tag function legal? <%! void

  • 0

Should be direct HTML printing in a JSP declaration tag function legal?

<%! void recursivePaintLevels(List<String> things, int deepLevel){ %>
    <ul class="level-<%=deepLevel%>">   
         <% for (int i=0; i<things.size(); i++){ %>
             <li class="whatever">
                             //(...)
            </li>
         <% } %>
    </ul>
<% } %>

And then call it like this in normal JSP body flow:

 //(...)
 <% recursivePaintLevels(things, 1); %>

I mean would be like using same normal JSP logic of implicit out.println() but in a method.
For me it is not working (Eclipse says ‘Syntax error, insert “Finally” to complete TryStatement’) but I am not sure if my error has something to do with it.

I also know I should use JSLT and EL, but this is my choice.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:51:39+00:00Added an answer on June 9, 2026 at 3:51 pm

    I believe this is pretty much legal and valid though a bad practice.I think the problem here is because of the double quotes "level-<%=deepLevel%>"
    Try separating that using

    <% String str= "level-"+deepLevel; %>
    

    and then use
    <ul class="<%=str%>"> .

    or simply replace the whole line with out.println

    EDIT:

    It appears that the body of the methods in jsp should not have any scriptlets. I have tried to embed one scriptlet with no content and observed that the generated java file adds the first part (from delcaration to the content before scriptlet )at the begging and the remaining part of the method at the end (and all member variables and other method declarations become part of this method). Apologies for providing wrong answer (as i have noticed that behavior with the cached jsp).

    Looks like out.prinltn is the only solution for this problem

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created a button using HTML/CSS and a Java script. The button should direct
The marketing people want to have the ability to write direct inline HTML in
I have a site with homepage as /var/www/mysite/index.html Now I want to direct www.mysite.com/x2312d
Is the ampersand the only character that should be encoded in an HTML attribute?
I'm comparing a string from the database to a list of strings in an
I need to style some HTML-Markup I have no direct control of and am
Should we declare the private fields as volatile if the instanced are used in
Should createUrl be called on controller or in views ? It doesn't matter? Or
Should I constantly have a session open in my web site with user accounts,
Should timestamps always use UTC (as in 2012-06-14T10:32:11+00:00 ) and not local time (as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.