JAVA-JSTL basics and java-jstl

Source: Internet
Author: User

JAVA-JSTL basics and java-jstl
What is JSTL?

 

JSTL (JSP Standard TagLibrary, JSP Standard tag Library) is a continuously improved open-source JSP tag library.

 

Why use JSTL?

 

JSP is very convenient for developing information display pages. You can also embed java code (scriptlet, expression, and Declaration) code to implement logical control. See the following program. However, this will cause the following problems:

Jsp maintenance is more difficult; error prompts are not clear, debugging is not easy; division of labor is not clear; (that is, jsp developers are artists and programmers );

Eventually increase the development cost of the program;


<% if (session.getAttribute(“user”).equals(“member”)) { %>  <p>Welcome, member!</p>  <% } else { %>  <p>Welcome, guest!</p>  <% } %>

Origin:

 

The original intention of JSTL is to separate front-end artists from development to achieve the goal of hierarchical development. We know that most artists are familiar with labels.


JSTL's biggest advantage

 

1: Make the Page code look more neat, display logic clear, unified style, easy to maintain

2: a large number of logical operations (such as iteration and judgment) provided by JSTL can greatly reduce the number of script codes (Scriptlets) in JSP.

3: it is a good idea to achieve layers!

4: it is easier for the artist to learn and master, because part of the work of the artist is to deal with various labels.

5: You can also customize the extension!


Disadvantages:


1. Added learning costs for front-end artists and maintenance staff

 

Introduction:

 

To use JSTL, you must reference the jstl. jar and standard. jar packages.

Add the following content to the top of the jsp file:


<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>   <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>  <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 

Main tag categories:

 

<C:> core tag Library

Includes expression-related labels, process tag creation when JSP page content is output, iterative operation tag, and URL tag generation and operation.

The JSTL core tag Library (C tag) has 13 tags and has four functions:

1. Expression control labels: out, set, remove, and catch

2. Process Control labels: if, choose, when, and otherwise

3. Loop labels: forEach and forTokens

4. URL operation tags: import, url, redirect

 

<Fmt:> Format the tag Library

Defines operations for formatting data (especially numbers and dates) and supports internationalization of JSP pages using localized resource bundle.


<Fn:> Function tag Library

Provides a set of commonly used EL functions, mainly used to process strings. These functions can be directly used in JSP.

 


JSTL is generally used together with EL, so let's take a look at EL.


EL (Expression Language) Objective: To make JSP writing easier


Syntax structure: $ {expression}

Example: <% = request. getParameter ("username") %> equivalent to $ {param. username}


Next we will apply JSTL to modify the jsp page:

 

Before using JSTL:


<td><select name="category" class="select1" id="category"><%for (int i=0; i<itemCategoryList.size(); i++) {ItemCategory ic = (ItemCategory)itemCategoryList.get(i);String selectedString = "";if (item.getItemCategory().getId().equals(ic.getId())) {selectedString = "selected";}%><option value="<%=ic.getId() %>" <%=selectedString %>><%=ic.getName() %></option><%}%></select></td>


After using JSTL:


<Td> <select name = "category" class = "select1" id = "category"> <! -- Traverse the list array and store the value in itemCategory --> <c: forEach items = "$ {itemCategoryList}" var = "itemCategory"> <c: set var = "selectedString"/> <! -- If item. itemCategory. id is equal to itemCategory. id --> <c: if test = "$ {item. itemCategory. id eq itemCategory. id}"> <! -- Store the selected value in the selectedString variable --> <c: set value = "selected" var = "selectedString"/> </c: if> <option value = "$ {itemCategory. id} "$ {selectedString }>$ {itemCategory. name }</option> </c: forEach> </select> </td>

Summary:


For JSTL, it further splits the jsp page and isolates the JAVA code in the jsp page. It is unnecessary for the artist to care about the implementation of java code, you only need to consider the beautification of the interface. In this way, there is a single responsibility and a clear division of labor.

During the summary of the DRP project, I deeply realized that many of the technologies we have learned are actually constantly expanding and extending in the abstract to increase the reusability and ease of use of the program! We are constantly abstracting, summing up, and learning through simplification! Make our programs more change-oriented!





After getting started with Java, what should I learn from the intermediate and advanced levels? What knowledge points should be mastered? The more you say, the better. You can only say that the introduction upstairs is clear.
At first, I learned about java basics J2SE. I already know J2SE. The better the basics of java, the easier it will be.
Want to learn about dynamic websites and mobile games
Dynamic Website J2EE, to learn jsp web page foreground beautification cssajax dynamic to learn frameworks struts, spring, hibernate. Like Learning struts first, learning more advanced than hibernate
On the mobile phone, applications mainly use the midlet for the use of J2SE. The difference is that java basic programming is similar to J2SE, and only a specific list box is displayed. You also need to learn how to connect with Bluetooth.
More?
I want to know about the basic learning of JAVA. It still takes a long time to find a job. I suggest you watch the video of Jack Ma from j2se. After you finish the j2se project, you can learn the database and then learn html, css, and JavaScript. jsp/servlet is also an introduction to web. It is used as a web project. After learning the framework, it will be interspersed with many things, such as xml, uml, log4j, and jUnit. when I die, I also need to think about how to learn and solve the problem. I must start by imitating other people's code. I have to write them several times. Only when I can write them out, I recommend that I start with something, including some common classes, some conceptual things, because I am more familiar with them

Horse soldiers video: http://www.verycd.com/topics/93279/
The database is looking for a different online address. You can find Jack Ma's Oracle and make a mistake.
The shopping project is also available from the beginning to the end.
It is important to start from the simple process to gradually understand the analysis and design of the project.

Learning java is also getting started from the video. You have to go to Thinking in java and look at Zhang Xiaoxiang's 《
Deep experience in JAVA Web development-core basics-detailed videos
For JavaScript, see JavaScript advanced programming. For html, simple css is also relatively simple. For css layout, it varies from person to person. For example, it is easy to understand. For some people, it is difficult to do more training with Dreamweaver. For example, you are familiar with the design mode. getting started

Supplement: Zhang Xiaoxiang's article 《
It's really wrong to thoroughly experience the JAVA Web development story-core basics, and JavaScript is fine enough and too much of its content (html, css and write-like) I have never read this java book. I know it. I also know that the video is actually a good reader.
I think the video of the horse soldiers is good, and I also talked about more learning methods. It's also about getting started. I want to watch a bunch of videos for Sun Xin, Zhang Xiaoxiang, and Ma's soldiers. the lecture method is suitable for decision-making by yourself. We recommend that you give a good speech to the horse soldiers.

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.