jsp页面的使用
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="students" scope="page" class="com.sxf.Student">
定义声明
<%students.setName("shxiinfa");
students.setAge(22);
%>
</jsp:useBean>
<%=students.getName()%>
<%=students.getAge()%>
<%!String name = "诸葛亮";
String password = "123456";%>
输出数据
<%=name%><%=password%>
定义方法
<%!public static int tt(int n) {if (n == 0) {
return 0;
} else if (n == 1) {
return 1;
} else {
return tt(n - 2) + tt(n - 1);
}
}%>
<%=tt(3)%>
定义类
<%!public class squre {double r;
squre(double r) {
this.r = r;
}
public double getarea() {
return r * r;
}
public double getlength() {
return r * 4;
}
}%>
类的方法的调用
<%=new squre(3).getarea()%><%=new squre(3).getlength()%>
页面的重定向
<%
String username=request.getParameter("name");
String password=request.getParameter("password");
if(username.equals("shixinfa")&&password.equals("123456")){%>
<jsp:forward page="success.jsp"></jsp:forward>
<%} else{%>
<jsp:forward page="error.jsp"></jsp:forward>
<% }
%>
提交表单
<form method="post" action="login.jsp">
账号:<input type="text" name="name"/>
密码:<input type="password" name="password"/>
<input type="submit" name="submit" value=""/>
</form>
</html>
javabean的使用:
<jsp:useBean id="student" class="com.sxf.Student" scope="page">
<jsp:setProperty name="student" property="*"/>
</jsp:useBean>
姓名:<jsp:getProperty property="name" name="student"/>
年龄:<jsp:getProperty property="age" name="student"/>
java类
package com.sxf;
public class Student {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}