jsp的基础编程

jsp页面的使用
<%@ page language=“java” contentType=“text/html; charset=UTF-8”
pageEncoding=“UTF-8”%>

Insert title here 定义声明 <% students.setName("shxiinfa"); students.setAge(22); %> <%=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>
<% }
%>
提交表单

账号: 密码: javabean的使用: 姓名: 年龄: 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;
}

猜你喜欢

转载自blog.csdn.net/weixin_37565521/article/details/82961280