displaying a list of entities in jsp file by using java

前端 未结 2 2006
无人共我
无人共我 2021-01-26 08:05

I am trying to display list of entities in a .jsp file, but I this error:

Unable to compile class for JSP: 

An error occurred at line: 28 in the jsp file: /gues         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-26 08:46

    You shouldn't be using scriptlets (those oldschool <% %> things with Java code) at all when using servlets and EL. Use taglibs like JSTL instead. It offers the tag to iterate over a collection.

    For example,

    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
    ...
    
        
    Drug Names Target Names
    ${fn:escapeXml(drugtarget.drug)} ${fn:escapeXml(drugtarget.target)}

    (note that I also fixed the rendering of table rows by putting the inside the loop)

    Much simpler, isn't it? You can by the way also just use instead of those functions.

    If you can, I suggest to add the following to your webapp's web.xml in order to disable scriptlets altogether so that you will be forced to do things the right way.

    
        
            *.jsp
            true
        
    
    

    See also:

    • How to avoid Java code in JSP files?

提交回复
热议问题