" 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.">
search
HomeJavaJavaBaseHow to write java in jsp

How to write java in jsp

Nov 13, 2019 pm 03:14 PM
javajsp

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: , usually declares global variables, constants, Methods, classes, note: the variables declared here are global

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

● JSP expression: , is the abbreviation of , 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment