javax.el.MethodNotFoundException: JSP method cannot be located

While compiling the JSP template, I encountered the following exception:

The method getFriendImage() is not recognized

I attempted to rebuild the class without success. The src attribute contains a valid link to an image that is functioning properly.

package classes;

public class Friends {

  private String username;
  private String friendname;
  private String complete;
  private String datestring;
  private String user_image;
  private String friendImage;
  private String online;

  public Friends(String username, String friendname, String complete, 
                 String datestring, String user_image, 
                 String friendImage, String online) {
    this.username = username;
    this.friendname = friendname;
    this.complete = complete;
    this.datestring = datestring;
    this.user_image = user_image;
    this.friendImage = friendImage;
    this.online = online;
  }

  public String getUsername() {
    return username;
  }

  public void setUsername(String username) {
    this.username = username;
  }

  public String getFriendname() {
    return friendname;
  }

  public void setFriendname(String friendname) {
    this.friendname = friendname;
  }

  public String getComplete() {
    return complete;
  }

  public void setComplete(String complete) {
    this.complete = complete;
  }

  public String getDatestring() {
    return datestring;
  }

  public void setDatestring(String datestring) {
    this.datestring = datestring;
  }

  public String getUser_image() {
    return user_image;
  }

  public void setUser_image(String user_image) {
    this.user_image = user_image;
  }

  public String getFriendImage() {
    return friendImage;
  }

  public void setFriendImage(String friendImage) {
    this.friendImage = friendImage;
  }

  public String getOnline() {
    return online;
  }

  public void setOnline(String online) {
    this.online = online;
  }
}

 session.setAttribute("friendsList", friendsList);

The JSP template snippet:

<ul id="friends_list">
    <c:forEach var="item" items="${friendsList}">
        <li class="friend_item"><img class="friend_list_image" 
            src="${friendsList.getFriendImage()}"  
            alt="friend_image"/>
            <label>${friendsList.getFriendname()}</label>
            <img class="message_icon" src="Images/Message.png" 
                 alt="Message_Icon" title="Message" onclick="message_friend()"/>
        </li>
    </c:forEach>
</ul>

Answer №1

It is not recommended to access those methods directly. The best practice is to use the field names you declared in your Friends class, assuming you have already set these variables.

When using var="item" in your <c:forEach, make sure to access them with ${item.somefieldname}.

<ul id="friends_list">
    <c:forEach var="item" items="${friendsList}">
        <li class="friend_item">
         <img class="friend_list_image" src="${item.friendImage}" alt="friend_image"/>
         <label>${item.friendname}</label>
         <img class="message_icon" src="Images/Message.png" alt="Message_Icon" title="Message" onclick="message_friend()"/>
        </li>
    </c:forEach>
</ul>

Pay attention to the capitalization:

  private String username;
  private String friendname;
  private String complete;
  private String datestring;
  private String user_image;
  private String friendImage; //capitalized here, be careful!
  private String online;

Answer №2

If you are looking to access the getFriendImage() method on individual instances of the Friend item, rather than on the entire list, you should do so like this:

src="${item.getFriendImage()}"

The same rule applies to the label, which should be:

<label>${item.getFriendname()}</label>

Also, it is recommended not to name the class as Friends in plural form. Creating a new (single) friend with new Friends() may be misleading, so sticking with the singular form Friend would be more appropriate.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the approach for incorporating JavaScript variables in Jade templates for writing inline CSS styles?

Struggling to inject CSS code dynamically? You're not alone. style(type='text/css') #header a#logo { background:url(constants.logo) no-repeat; } @media only screen and (-webkit-min-device-pixel-ratio: 1.5) { #header a#logo { ...

Tips for finding information within a table using HTML

My task involves creating a table with the option for users to search data within it. However, I have encountered an issue where I am only able to search for data in the first row of the table. <table style="width:100%" id="table"> <tr> ...

Tips for triggering jquery code when a variable containing a CSS attribute is modified

I have a specific requirement where I need to reset the scrollleft value to 0 on my wrapper whenever a particular CSS property changes. Although I am new to using jQuery and haven't worked with variables much, I believe I need to create a variable to ...

What is the best way to ensure that all the divs within a grid maintain equal size even as the grid layout changes?

I have a grid of divs with dimensions of 960x960 pixels, each block is usually 56px x 56px in size. I want to adjust the size of the divs based on the changing number of rows and columns in the grid. Below is the jQuery code that I am using to dynamicall ...

Ensure the item chosen is displayed on a single line, not two

I've encountered an issue with my select menu. When I click on it, the options are displayed in a single line. However, upon selecting an item, it appears on two lines - one for the text and another for the icon. How can I ensure that the selection re ...

Use the inline IF statement to adjust the icon class depending on the Flask variable

Is it feasible to achieve this using the inline if function? Alternatively, I could use JavaScript. While I've come across some similar posts here, the solutions provided were not exactly what I expected or were implemented in PHP. <i class="f ...

VSCODE's intellisense feature seems to be ignoring CSS code within JSX files

I've been puzzling over why Visual Studio Code isn't recognizing CSS syntax inside JSX files. While I'm typing, CSS IntelliSense doesn't provide suggestions for CSS - only Emmet suggestions.https://i.stack.imgur.com/FegYO.png Despite t ...

Tips for adjusting the content direction of a Popover

I am currently working on a component that includes the following code: import { Popover, PopoverTrigger, PopoverContent, PopoverBody, Portal, Button, } from "@chakra-ui/react"; import { ReactNode } from "react"; import { Co ...

Trouble with saving the positioning after drag and drop

I am currently facing an issue with my drag-and-drop script where the coordinates of positioned relative divs are not being saved in the same position when I reload. These divs are contained within a container with specific height and width, restricting t ...

Can search criteria be saved for later use?

I operate a classifieds website that allows users to search through ads. I am contemplating ways to save search criteria so that users can easily reuse them for future searches without having to input the same details over and over again. For instance, th ...

Guide on applying CSS to option tag within a select element in VUE.js

I am attempting to design a dropdown menu that resembles the one shown in the image. However, I'm currently unable to include any CSS styling. Can anyone provide guidance on how to create a customizable select dropdown in Vue? https://i.stack.imgur.c ...

Pattern matching to locate text that is not enclosed within HTML tags and does not fall within certain specified tags

I am attempting to create a regular expression that will match specific words located outside and between HTML tags (but not within the tags themselves). However, I also need to ensure that these words are excluded when they appear between heading tags suc ...

Responsive Navigation Menu using Bootstrap Framework for mobile devices

I am encountering an issue with my bootstrap navbar where the button does not appear on the mobile version. This is happening while testing on my Windows Phone. Below is the code for my navbar: <nav class="navbar navbar-default navbar-fixed-top" ro ...

CakePHP does not recognize the input type "number" in forms

My goal is to create a form field that only accepts numbers as input. However, when I attempt the following code in CakePHP: <?php echo $this->Form->input('aht',array( 'label' => 'AHT', 'type' = ...

html inserting line break using label

I am attempting to dynamically set text to a label using jQuery. However, I am having trouble getting the <br> or \n to create new lines. Instead, all the text displays on the same line and wraps around. If you want to see my code in action, ch ...

Changing the color of the timePicker clock in material-ui: a step-by-step guide

I have been attempting to update the color of the time clock in my timeInput component (material-ui-time-picker) for material-ui, but unfortunately, it is not reflecting the change. Here is the code I am using: <TimeInput style ={heure} ...

Sorting outcomes based on HTML file

Attempting to narrow down results based on certain criteria within a large HTML file. Unsure if my query is attainable, but it never hurts to inquire. Currently immersed in a browser game featuring a vast map measuring 100x100, with each pixel representing ...

What is the best way to implement a scrollbar in a specific div rather than the entire window?

Hey everyone! So, I have this window in electronJS with a div where I'm dynamically adding elements using Javascript and the function --> document.createElement('section'). Here's the loop in Javascript to add these elements: for (var ...

ways to access a designated nodal point in angularJS from a constantly updating data source

I am in need of assistance with how to open a specific node using angularJS from a dynamic data source. I have been able to toggle (hide/show) the sub nodes, but what I would like is for clicking on a specific node to only show its sub-nodes. Currently, wh ...

The following code is experiencing difficulties when running on the Chrome browser

https://i.stack.imgur.com/GjG7r.pngI have developed a function that can click the checkbox of a specific row and retrieve the text from that row. CheckBoxXpath-> private static final String XPATH_JOBRATECATEGORIES_CHECKBOX_LIST = "//kendo-grid-list// ...