博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JSP之JavaBean
阅读量:5266 次
发布时间:2019-06-14

本文共 3485 字,大约阅读时间需要 11 分钟。

package com.po;public class Users {	private String username;	private String password;	public Users(){			}	public String getUsername() {		return username;	}	public void setUsername(String username) {		this.username = username;	}	public String getPassword() {		return password;	}	public void setPassword(String password) {		this.password = password;	}	}
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%><%@ page import="com.po.Users" %><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>              My JSP 'index.jsp' starting page	

普通方式使用JavaBean


<% Users user = new Users(); user.setName("admin"); user.setPassword("123456"); %> <%=user.getName() %>
//login.jsp<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>              My JSP 'login.jsp' starting page    	
用户名:
密码:
//dologin.jsp<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>              My JSP 'index.jsp' starting page	

useBean标签使用JavaBean


<%-- --%>
<%--
--%> <%--
--%> <%--
--%>
<%--使用传统表达式的方法获取username与password --%> <%-- <%=myUser.getUsername() %> <%=myUser.getPassword() %> --%> 用户名:
密码:
測试作用域 <% request.getRequestDispatcher("testScope.jsp").forward(request, response); %>

//testScope.jsp<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%><%@ page import="com.po.Users" %><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>              My JSP 'testScope.jsp' starting page    	
<%--
<%=((Users)application.getAttribute("myUser")).getUsername() %> <%=((Users)application.getAttribute("myUser")).getPassword() %> --%> <%--
<%=((Users)session.getAttribute("myUser")).getUsername() %> <%=((Users)session.getAttribute("myUser")).getPassword() %> --%> <%--
<%=((Users)request.getAttribute("myUser")).getUsername() %> <%=((Users)request.getAttribute("myUser")).getPassword() %> --%>
<% String username = ""; String password = ""; if(request.getAttribute("myUser")!=null){ username = ((Users)request.getAttribute("myUser")).getUsername(); password = ((Users)request.getAttribute("myUser")).getPassword(); } %> 用户名:<%=username %> 密码:<%=password %>

转载于:https://www.cnblogs.com/jzdwajue/p/6978411.html

你可能感兴趣的文章
283. Move Zeroes把零放在最后面
查看>>
Visual Studio Code 打开.py代码报Linter pylint is not installed解决办法
查看>>
Python 数据类型
查看>>
centos下同时启动多个tomcat
查看>>
slab分配器
查看>>
【读书笔记】C#高级编程 第三章 对象和类型
查看>>
针对sl的ICSharpCode.SharpZipLib,只保留zip,gzip的流压缩、解压缩功能
查看>>
【SVM】libsvm-python
查看>>
Jmeter接口压力测试,Java.net.BindException: Address already in use: connect
查看>>
Leetcode Balanced Binary Tree
查看>>
go:channel(未完)
查看>>
[JS]递归对象或数组
查看>>
多线程《三》进程与线程的区别
查看>>
linux sed命令
查看>>
html标签的嵌套规则
查看>>
[Source] Machine Learning Gathering/Surveys
查看>>
HTML <select> 标签
查看>>
tju 1782. The jackpot
查看>>
湖南多校对抗赛(2015.03.28) H SG Value
查看>>
hdu1255扫描线计算覆盖两次面积
查看>>