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

How to write java in jsp

angryTom
Release: 2019-11-13 15:14:40
Original
2755 people have browsed it

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

● JSP Scriptlet: <%java code%>, which can include local variables and java statements

● JSP expression: <%=java code%>, <%=variable%> is the abbreviation of <% out.println(variable) %>, 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"%>
Copy after login

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" %>
Copy after login

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template