Search code examples
javaeclipsejspstruts

Syntax Error in my JSP Eclipse


Why I have this error in my JSP file

My JSP:

enter image description here

Error Message:

Syntax error, insert "}" to complete MethodBody


Solution

  • A JSP has been parsed incorrectly by Eclipse. It has mistreated curly braces used by some javascript code that was rendered without <script> tag.

    The <script> tag should be placed inside the <head> or <body> tags.

    JSP files are compiled to a servlet. If you declare a method inside the JSP page using scriptlets, the method body is opened with { and should be closed with }, but somwhere in the code you might find /*}*/, or even worse missing <%}%>. The example of such errors (redundant }; in the Java code) you can find here.

    To resolve this and other possible errors caused by spaghetti code inside the JSP, recommended way is to not use scriptlets and move Java code to a servlet. Struts is MVC framework that provided additional to servlets features for rendering JSP pages. You have to move Java code from JSP page to Struts controllers and access it by expression languages like JSTL, OGNL, etc. Return JSP page as a result/forward of the action/controller execution/ method call. You can also call methods of the model/controller directly while the page is rendered. This behaviour is out of the scope in which MVC pattern is used.

    If you need more information about separation of concerns while developing a web application, particularly related to how to avoid Java code in JSP see How to avoid Java code in JSP files.