facebook

Problems understanding static include directive in JSPs

  1. MyEclipse Archived
  2.  > 
  3. Bugs
Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #266075 Reply

    JohnL4
    Member

    Howdy. I’m trying to pull some ancient JSPs into MyEclipse 5.1, and it can’t seem to understand that I’ve imported classes in a statically-included JSP fragment. Inside the fragment, I import some of my Java classes, but in the includING JSP, variables declared of those types generate “can’t find class definition”-type errors.

    I’ve seen posting on here going back several years about this issue. Has it been fixed yet? Do I have declare my page to be of a particular type (e.g., XHTML 1.0 strict, HTML 4.01 transitional, etc.)?

    #266153 Reply

    JohnL4
    Member

    Hey crew, sorry to push this, but it’s been a couple of days and I’ve gotten no replies, no request for clarification, no “works for me”, nada.

    Is this the right forum? Should I just go ahead and try to file a bug report?

    Thanks.

    John.

    #266191 Reply

    Greg
    Member

    Hey John,

    Sorry, I meant to get to your post yesterday but just forgot. Could you post 2 small example JSP pages that illustrate the issue so we can reproduce on our end?

    Thanks

    #266370 Reply

    JohnL4
    Member

    StdImports.jsp:

    
    <%@ page import="java.util.Date" %>
    

    ShowDate.jsp:

    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <%@ include file="StdImports.jsp" %>
    
    <html>
    <head>
    <title>$Workfile: ShowDate.jsp$</title>
    </head>
    <body>
    
    <p>The current date/time is <%= new Date() %>.
    
    </body>   
    </html>
    

    Validation flags the “new Date()” as an error because it can’t resolve the class, but this works fine in my container (JBoss 4.0.1).

    Thanks.

    #266777 Reply

    JadedGamer
    Member

    We had (almost) the same problem when we included a .jspf that imported and used some classes not used in the including file. Then validation of the including file complained that those classes were unknown. (E.g. the .jspf had <jsp:directive.page import=”com.foo.Fie”/> and there was an error entry under problems for the .jsp, on the line of the <%@include %> that said that “Fie” cannot be resolved.) This is using 5.1 GA, haven’t tried 5.5 M1 yet.

    Does the validator check only for imports in the initial document? The spec says page directives can be anywhere in the document and apply to the whole of the document. Tomcat’s JSP compiler has no problems with the code as is.

    #266803 Reply

    Riyad Kalla
    Member

    Try moving the includes to the top of the page

    #267301 Reply

    Amos
    Member

    Hi,

    This problem is not only specific to class imports, it seems it’s a general problem with jspf includes. I’ve just upgraded to 5.1.1 (clean all-in-one install) from 4.1.1 (yes, I know, it’s been a while between upgrades), and now I get error markers in just about all my jsp files because imported jspfs aren’t resolved.

    The class import problem mentioned by John seems to be one symptom; I get two more:

    1. I have a line like

    <%@ include file="/util/top.jspf" %>

    in most of my jsps. When I place the cursor within the quotes, I used to be able to open the referenced jspf by hitting F3. This no longer works in 5.1.1.

    2. Let’s say my top.jspf declares a variable someVariable. If I then have

    <%=someVariable%>

    in another jsp after the abovementioned include line, I get a “someVariable cannot be resolved” validation error.

    Running the project in Tomcat works perfectly fine, i.e. the imports are properly resolved and the resulting …_jsp.java files are built as expected.

    Apart from that, I’m noticing some great improvements to taglib handling – I used to get hundreds of warnings about taglib tags that weren’t recognised in 4.1.1; they’re now gone and I even get the correct tooltips describing the tags.

    I’ll have to keep working in 4.1.1 for now because I don’t want to turn off validation altogether in 5.1.1 but the incorrect error markers are just too annoying. Would be great if the import problem could be resolved…

    Cheers,

    Amos

    #267314 Reply

    Riyad Kalla
    Member

    in most of my jsps. When I place the cursor within the quotes, I used to be able to open the referenced jspf by hitting F3. This no longer works in 5.1.1.

    Can you hold down CTRL and click on the link? That should open it… if MyEclipse cannot open it, then the problem is that it cannot resolve the file. In which case two things could be the issue here:

    1) Your project is a plain Java project and not a web project, so MyEclipse cannot resolve file locations.
    2) Try using a relative file path and not an absolutel file path.

    #267361 Reply

    Amos
    Member

    Hi Riyad,

    Thanks for the reply. You’re correct, I’d imported the project as a simple Java project. The link to the imported jspf worked once I added web project capabilities (although it worked in 4.1.1 without them, i.e. as a Java project), both via F3 and via Ctrl+click. The file path remained absolute (from the web root).

    However, the validation errors were still there, so I tried to run the validator again. As soon as I do that, MyEclipse 5.1.1 runs the validation and won’t stop… If I look at the progress tab, I can see three validation types running simultaneously (HTML/JSP/JSP semantics for JSF, though I don’t use JSF). Trying to cancel the operations locks up MyEclipse and it stops reacting to anything – so after about 10 minutes, I finally killed the process. Maybe the validation threads are locking up each other’s resources?

    I did a bit of testing, and it seems I can run the validation for single files without it locking up, but not for the project. Luckily, selecting multiple files seems to work as well, otherwise it would’ve been quite a task… 🙂

    And the validation seems to work as it should, so thanks for the tip about making it a web project. As long as I know not to validate the project, I can live with having to validate multiple files manually, especially since it doesn’t happen too often.

    Cheers,

    Amos

    P.S.: Out of curiosity, if you’re still following this thread, John, does making your project a web project resolve your class import problem as well?

    #267379 Reply

    Riyad Kalla
    Member

    The link to the imported jspf worked once I added web project capabilities (although it worked in 4.1.1 without them, i.e. as a Java project), both via F3 and via Ctrl+click. The file path remained absolute (from the web root).

    Thanks for doing that. We tightened up some restrictions because a lot of folks were getting the impression that Java Project was just as good as a Web Project and that just isn’t the case. So we changed some code to still work with Java Projects but really do require that folks add Web Caps in most cases.

    However, the validation errors were still there, so I tried to run the validator again. As soon as I do that, MyEclipse 5.1.1 runs the validation and won’t stop… If I look at the progress tab, I can see three validation types running simultaneously (HTML/JSP/JSP semantics for JSF, though I don’t use JSF). Trying to cancel the operations locks up MyEclipse and it stops reacting to anything – so after about 10 minutes, I finally killed the process. Maybe the validation threads are locking up each other’s resources?

    Hmm sounds fishy. Try this instead:

    1) Right click on the root of the project and do a refresh
    2) Go to Project > Clean > Select your project and clean it, let it rebuild. That will automatically clear all error markers and re-run validation.

    #267415 Reply

    Amos
    Member

    Yep, that did it. After I’d cleaned the project, maually running the validation again worked without any lock-ups as well. Thanks, Riyad! 🙂

    #267417 Reply

    Riyad Kalla
    Member

    I’m glad it’s working now, thanks for following up.

    #272141 Reply

    Amos
    Member

    Sorry to drag this topic out again, but in 5.5.1 I’ve now got the same problem again, i.e. validation errors all over my JSPs because it’s not considering the imported JSPFs. The project was created from the existing source code, so it correctly recognised it as a web project. I’ve tried refresh/clean/validate and it still ignores variables that are set for most JSPs in one JSPF that’s being imported (as described in a previous post above).

    Any ideas would be appreciated.

    #272199 Reply

    Riyad Kalla
    Member

    aaamos,
    First thing to check is to make sure the Web Capabilities transfered over *and* are setup correctly. If you open the project properties and go to MyEclipse > Web ,make sure the Web Root directory is setup accurately to be the directory that contains the WEB-INF directory.

    #272226 Reply

    Amos
    Member

    Web Root was correctly set up (to “/”), but I removed and re-added web project capabilities anyway, then did another refresh and a clean project just to be sure. Still getting the same validation errors.

Viewing 15 posts - 1 through 15 (of 17 total)
Reply To: Problems understanding static include directive in JSPs

You must be logged in to post in the forum log in