编写一个jsp程序,实现将用户信息保存在application对象的用户注册
1 package com.sp.test; 2 3 public class User { 4 5 private String usename; 6 private String password; 7 8 public String getUsename() { 9 return usename; 10 } 11 public void setUsename(String usename) { 12 this.usename = usename; 13 } 14 public String getPassword() { 15 return password; 16 } 17 public void setPassword(String password) { 18 this.password = password; 19 } 20 public User(String usename, String password) { 21 super(); 22 this.usename = usename; 23 this.password = password; 24 } 25 26 27 }
1 <%@page import="com.sp.test.User"%> 2 <%@ page language="java" contentType="text/html; charset=UTF-8" 3 pageEncoding="UTF-8"%> 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 5 <html> 6 <head> 7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 8 <title>用户的注册信息</title> 9 </head> 10 <body> 11 <% 12 Object obj = application.getAttribute("use"); 13 if(obj == null){ 14 User u = new User("张三","123"); 15 application.setAttribute("use", u); 16 obj = u; 17 } 18 User us = (User)obj; 19 //输出用户信息 20 out.println("用户名:" + us.getUsename() + "<br>密码:" + us.getPassword()); 21 %> 22 </body> 23 </html>