put static keyword inside the JSP scripplets error

M

Matt

I put static keyword inside the JSP scripplets, and it has Generated
servlet error "illegal start of expression."

<%
static ConnectorLogger logger = ConnectorLogger.getLogger();
%>

Any ideas??

Generated servlet error:
C:\Projects\.metadata\.plugins\com.ibm.etools.server.core\tmp0\cache\localhost\server1\extendedguiApp\extendedgui.war\attachdoc\_NewAttachDocAction.java:101:

illegal start of expression
static ConnectorLogger logger =
ConnectorLogger.getLogger();

please help. thanks!!
 
A

Andrew Thompson

I put static keyword inside the JSP scripplets, and it has Generated
servlet error "illegal start of expression."

<%
static ConnectorLogger logger = ConnectorLogger.getLogger();
%>

Any ideas??

...take it out.

( Instead you might use an 'application' scope bean that
creates the (single) logger, but I doubt that is the correct
way to go about doing it. )
 
S

Sudsy

Matt said:
I put static keyword inside the JSP scripplets, and it has Generated
servlet error "illegal start of expression."

<%
static ConnectorLogger logger = ConnectorLogger.getLogger();
%>

Any ideas??

Sure! Look up the difference between declarations and scriptlets.
Anything within <% and %> gets inserted into the _jspService
method. Does it make any sense to specify static for a method
variable? Remember, this isn't C.
Try it in a small class and you'll find the compiler complains
with the same message, to wit "illegal start of expression".
Solution? Make it a declaration. Try this:

<%!
static ConnectorLogger logger = ConnectorLogger.getLogger();
%>

Note the exclamation mark.
 
Joined
Sep 14, 2011
Messages
2
Reaction score
0
More explanation

please explain the difference between

<%! int a=1; %>
and,
<%
int a=1;
%>

Matt wrote:
> I put static keyword inside the JSP scripplets, and it has Generated
> servlet error "illegal start of expression."
>
> <%
> static ConnectorLogger logger = ConnectorLogger.getLogger();
> %>
>
> Any ideas??

Sure! Look up the difference between declarations and scriptlets.
Anything within <% and %> gets inserted into the _jspService
method. Does it make any sense to specify static for a method
variable? Remember, this isn't C.
Try it in a small class and you'll find the compiler complains
with the same message, to wit "illegal start of expression".
Solution? Make it a declaration. Try this:

<%!
static ConnectorLogger logger = ConnectorLogger.getLogger();
%>

Note the exclamation mark.

--
Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top