JSP Basic usage

Source: Internet
Author: User

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
<%@ taglib prefix= "C" uri= "Http://java.sun.com/jsp/jstl/core"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >


<title>my JSP ' demo1.jsp ' starting page</title>


<body>
<%out.println ("First JSP program");%>
< interactivity!--Web pages--
<form action= "demo1.jsp" method= "POST" >
Input display: <input type= "text" name= "info" >
<input type= "Submit" value= "Show input" >
</form>
<!--Get what you've entered--
<%
Set the encoding to prevent Chinese garbled characters from appearing
Request.setcharacterencoding ("Utf-8");
String str=request.getparameter ("info");
Out.println ("%>
<!--JSP Basics: Annotate -
<!--This comment, the client can see-
<%--This JSP comment, the client cannot see--%>
<%
Java-provided single-line comment, client not visible
/*
A multi-line comment from Java that the client can see
*/
%>
<!--The first code block tag --
<%
int x=10;
String str1= "Hello,world";
Out.println ("x=" +x);
Out.println ("str1=" +str1);
%>
<!--The second code block tag: Global variables, methods, classes (not recommended here) --
<%!
public static String str2= "Hello,china";
public int Add (int x,int y) {
return x+y;
}
Class person{
private String name;
private int age;
Public person (String Name,int age) {
This.name=name;
This.age=age;
}
Public String Totell () {
return name+age;
}
}
%>
<!--here to call the method written above--
<%
Out.println (STR2);
Out.println (Add (2,3));
Out.println (New person ("Zhangsan", 5));
%>
<!--The third code block tag --
<%
String str3= "Spring";
int a=10;
%>
<!--advocates the use of this method output--
&LT;H3&GT;STR3=&LT;%=STR3%>

<!--case: HTML and Java Code Advocate separation --
<table border= "1px" width= "500px" height= "500px" >
<%
int rows=10;
int cols=10;
for (int x1=0;x1<rows;x1++) {
%>
<tr>
<%
for (int y=0;y<cols;y++) {
%>
<td><%= (x1*y)%></td>
<%
}
%>
</tr>
<%
}
%>
</table>
<%--
<!--a form that defines the number of rows and columns of the input table--
<form action= "demo1.jsp" method= "POST" >
<table border= "1" width= "100%" >
<tr>
<td> Enter the number of table rows to display </td>
<td><input type= "text" name= "Row" ></td>
</tr>
<tr>
<td> Enter the number of table columns to display </td>
<td><input type= "text" name= "col" ></td>
</tr>
<tr>
&LT;TD colspan= "2" >
<input type= "Submit" value= "Submission" >
<input type= "reset" value= "reset" >
</td>
</tr>
</table>
</form>
Receive the data passed above, print the form <br/>
<table border= "1" width= "100%" >
<%
int rows1=0;
int cols1=0;
try{
Rows=integer.parseint (Request.getparameter ("Row"));
Cols=integer.parseint (Request.getparameter ("col"));
}catch (Exception e) {}
for (int x2=0;x2<rows1;x2++) {
%>
<tr>
<%
for (int y=0;y<cols1;y++) {
%>
<td><%= (x2*y)%></td>
<%
}
%>
</tr>
<%
}
%>
</table>

--%>

The code is opened and placed on two JSP pages for display.

</body>

If there are errors and suggestions please speak out, together learn progress to make friends.

qq:1327880701

Copyright Notice: Bo Master original articles, reproduced please indicate the source. Http://blog.csdn.net/dzy21

JSP Basic usage

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.