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 593273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:49:42+00:00 2026-05-13T15:49:42+00:00

Please don’t punch me in the face! I know this flies in the face

  • 0

Please don’t punch me in the face! I know this flies in the face of good design, but I’m simply writing a test page to demonstrate something. Our webapp module (correctly) has no direct access to our domain classes. I don’t want to create a whole class outside of the JSP, since the page is just for demonstration purposes, and I don’t want to write a lot of extraneous code for the same reason. I was trying to define a class the usual way in the JSP, but that didn’t work (threw a lot of compile-time errors). This is a quick-n-dirty, one-time deal (I’ll be getting rid of it once I’m done). I’d just like to know if this is possible or not. If not, then I will go the long way.

<%

 public class Person {
    private int id;
    private int age;
    private String name;

    /*
      ... ctor and getters and setters
    */

 }
%>

And the errors I got:

convert-jsp-to-java:
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------

An error occurred at line: 57 in the generated java file
Syntax error on token "class", invalid VariableDeclarator

An error occurred at line: 73 in the generated java file
The return type is incompatible with Object.getClass()

An error occurred at line: 74 in the generated java file
Syntax error on token "class", Identifier expected

An error occurred at line: 77 in the generated java file
Syntax error on token "class", invalid VariableDeclaratorId

An error occurred at line: 78 in the generated java file
Syntax error on token "this", PrimitiveType expected

An error occurred at line: 78 in the generated java file
Syntax error on token "class", invalid Expression

An error occurred at line: 79 in the generated java file
Syntax error on token "class", invalid Expression
  • 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-05-13T15:49:42+00:00Added an answer on May 13, 2026 at 3:49 pm

    I don’t see why it wouldn’t be possible. A JSP is just another way of writing a Servlet, so you should be able to create classes as static (or for that matter, non-static) inner classes within the Servlet, as you would any other class, using the <%! %> convention.

    I was able to do a quick, functional, proof of concept:

    <%@page contentType="text/html" pageEncoding="MacRoman"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <%!
    private static class NdBadIdea {
      private final int foo = 42;
    
      public int getFoo() {
        return foo;
      }
    }
    %>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=MacRoman">
            <title>JSP Page</title>
        </head>
        <body>
            <h1>Hello World!</h1>
            <%=new NdBadIdea().getFoo()%>
        </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please don't crucify me for this one. I decided it might be good to
I have a flash element (I know, but please don't) with a settings.xml file.
I know it will sound strange but please don't mind: In C#, let's say
Firstly, please don't dismiss this question - I'm aware it's an ugly situation but
Now, I know this is completely subjective, so please don't flame me. I've never
OK. this might be a very basic question to please don't flame me but
Update3: If you like this posting please don't upvote me but upvote the genius
I know this is a rather odd question, please don't flame me :) I
Please don't confuse with the title as it was already asked by someone but
Full disclosure: this is for an assignment, so please don't post actual code solutions!

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.