" for declaration statements, usually global variables, constants, methods; 2. Use "<%java code%>" for writing local variables and java statements; 3. Use "<%=java code%>" for jsp expression, please note that it cannot be followed by a semicolon."/> " for declaration statements, usually global variables, constants, methods; 2. Use "<%java code%>" for writing local variables and java statements; 3. Use "<%=java code%>" for jsp expression, please note that it cannot be followed by a semicolon.">

Home>Article>Java> How to write java in jsp

How to write java in jsp

angryTom
angryTom Original
2019-11-13 15:14:40 2650browse

How to write java in jsp

How to write java in jsp

You can write Java code in jsp. The specific writing method is introduced below. I hope it will help You guys are helpful.

Writing

● JSP declaration statement:f964c82c00da9b2d6ff613f0bd550dae, usually declares global variables, constants, Methods, classes, note: the variables declared here are global

● JSP Scriptlet:ecd5b2ea7228ff22666b55fc713deff4, which can include local variables and java statements

● JSP expression:b7ac12e2212eeaeb699431829f0a52aa, 6585de3afd64c80af2cd10cad4828737 is the abbreviation of 01cb4a40223fa606ccf716a7d2cc5445, please note : The expression here cannot be followed by a semicolon

(recommended tutorial:java tutorial)

Three instructions are defined in jsp2.0: page instruction, include instruction, and taglib instruction.

1. Regarding the page command, what we usually see most is this:

<%@page contentType="text/html;charset=gb2312" import="java.util.Date"%>

Mainly used for: setting encoding and importing jar packages

2. About The include directive is used to introduce other jsp pages. The jsp engine will translate two jsps into one servlet, so it is also called static introduction

3. Regarding the taglib directive, it defines a tag library and its customization The prefix of the label. For example, we commonly use c:foreach. First import the jstl package, and then add this tag to the jsp:

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

Then you can use c:foreach

Example:

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <% String M=session.getAttribute("sysname").toString(); //从session里把值拿出来,并赋值给M %> < div class = "navbar-header pull-left" > < a href = "javascript:;" class = "navbar-brand" > < small > < i class = "fa fa-leaf" > < /i> <%=M%> < /small> < /a> < /div>

The above is the detailed content of How to write java in jsp. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn