JSTL tag error: & lt; c: forEach var = & quot; book & quot; items = & quot ;$ {requestScope. books} & quot; varStatus = & quot; status & quot; & gt;, jstlvarstatus

Source: Internet
Author: User

Error in JSTL label: <c: forEach var = "book" items = "$ {requestScope. books}" varStatus = "status">, jstlvarstatus

An error occurred while running the JSTL label code in the book today. The following is a summary:

Question 1.The JSP specification requires that an attribute name is preceded by whitespace 

Solution: <c: forEach var = "book" items = "$ {requestScope. books}" varStatus = "status"> Error

Changed to: <c: forEach var = "book" items = "$ {requestScope. books}" varStatus = "status">

Cause: Add a space before varStatus = "status"

------------------------------------------------------------------

Problem 2. Property 'isbn 'not found on type java. lang. String

Solution: <c: forEach var = "book" items = "$ {requestScope. books}" varStatus = "status"> Error

Changed to: <c: forEach var = "book" items = "$ {requestScope. books}" varStatus = "status">

Cause: Remove spaces before $ {requestScope. books}

------------------------------------------------------------------

Problem 3: The program is running and jsp is accessible, but the EL expression cannot read the desired information.

Solution: The servlet <url-pattern> information is not added to the. xml configuration file,You cannot call servlet to send objects to jsp.

Add the following content to the. xml file:

<servlet>   <servlet-name>BooksServlet</servlet-name>   <servlet-class>com.controller.BooksServlet</servlet-class></servlet><servlet-mapping>   <servlet-name>BooksServlet</servlet-name>   <url-pattern>/BooksServlet</url-pattern></servlet-mapping>

------------------------------------------------------------------

Jstl label exercise code:

1. BooksServlet. java

1 package com. controller; 2 import java. io. IOException; 3 import javax. servlet. requestDispatcher; 4 import javax. servlet. servletException; 5 import javax. servlet. annotation. webServlet; 6 import javax. servlet. http. httpServlet; 7 import javax. servlet. http. httpServletRequest; 8 import javax. servlet. http. httpServletResponse; 9 import java. util. list; 10 import java. util. arrayList; 11 import com. model. book; 12 // @ WebServlet ("/BooksServlet") 13 public class BooksServlet extends HttpServlet {14 @ Override15 public void doGet (HttpServletRequest request, HttpServletResponse response) 16 throws ServletException, IOException {17 List <Book> books = new ArrayList <Book> (); 18 Book book1 = new Book ("978-7-302-23059-5 ", "Java programming language", 45.00); 19 Book book2 = new Book ("978-7-302-21540-0", "Java Web Programming Technology", 39.00 ); 20 Book book3 = new Book ("978-7-302-24130-0", "C # entry classic", 99.80); 21 books. add (book1); 22 books. add (book2); 23 books. add (book3); 24 request. setAttribute ("books", books); 25 RequestDispatcher rd = request. getRequestDispatcher ("/books. jsp "); 26 rd. forward (request, response); 27} 28}

2. Book. java (javaBean class)

 1 package com.model; 2  3 public class Book { 4    private String isbn; 5    private String title; 6    private double price; 7    public Book(String isbn, String title, double price) { 8     super(); 9     this.isbn = isbn;10     this.title = title;11     this.price = price;12     }13     public String getIsbn() {14         return isbn;15     }16     public void setIsbn(String isbn) {17         this.isbn = isbn;18     }19     public String getTitle() {20         return title;21     }22     public void setTitle(String title) {23         this.title = title;24     }25     public double getPrice() {26         return price;27     }28     public void setPrice(double price) {29         this.price = price;30     }31         32    33 }

3. books. jsp

 1 package com.model; 2  3 public class Book { 4    private String isbn; 5    private String title; 6    private double price; 7    public Book(String isbn, String title, double price) { 8     super(); 9     this.isbn = isbn;10     this.title = title;11     this.price = price;12     }13     public String getIsbn() {14         return isbn;15     }16     public void setIsbn(String isbn) {17         this.isbn = isbn;18     }19     public String getTitle() {20         return title;21     }22     public void setTitle(String title) {23         this.title = title;24     }25     public double getPrice() {26         return price;27     }28     public void setPrice(double price) {29         this.price = price;30     }31         32    33 }

4. configuration file. xm

 1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> 3   <display-name>Ex_JSTL_tag</display-name> 4   <servlet> 5     <servlet-name>BooksServlet</servlet-name> 6     <servlet-class>com.controller.BooksServlet</servlet-class> 7   </servlet> 8   <servlet-mapping> 9     <servlet-name>BooksServlet</servlet-name>10     <url-pattern>/BooksServlet</url-pattern>11   </servlet-mapping>12   <welcome-file-list>13     <welcome-file>index.html</welcome-file>14     <welcome-file>index.htm</welcome-file>15     <welcome-file>books.jsp</welcome-file>16     <welcome-file>default.htm</welcome-file>17     <welcome-file>default.jsp</welcome-file>18   </welcome-file-list>19 </web-app>

5. Add http: // localhost/Ex_JSTL_tag/during running/BooksServlet

Only when/BooksServlet is added to the url can the servlet be called.

:

 

 

Originality is not easy. For reposted content, please declare the original address.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.