JavaWeb13.标准标签

回顾:JavaWeb12.三层架构项目集成

目录

使用web.xml设置网页首选项

jsp的标准标签

jsp的常用标签

useBean的用法

setProperty的用法

jsp标准标签的使用


使用web.xml设置网页首选项

首先在创建项目时,点击next出现下方页面,需要勾选Generate web.xml deployment descriptor 这个选项,创建web.xml文件

然后在此项目的目录下会生成一个web.xml的文件

web.xml文件所在路径:项目文件夹->src->main->webapp->WEB-INF->web.xml

 

 双击点开并打开Source界面

在此界面下中 welcom-file-list 标签下查询界面顺序为从上至下,可以删除多余标签留下一个需要为首选项的标签,内容为需要访问的文件名即可

注意:修改了 web.xml 文件,其项目必须重新在服务器上重新启动


jsp的标准标签

jsp的常用标签

  1. <jsp:include page="页面">  作用:使这个页面包含其他页面
  2. <jsp:param name="name" value="value">  作用:将参数传递给其他页面
  3. <jsp:foward page="页面"> 作用:转发至其他页面
  4. <jsp:useBean>  作用:实例化一个对象
  5. <jsp:setProperty> 作用:给useBean属性设置值
  6. <jsp:getProperty> 作用:在useBean中取值

useBean的用法

<jsp:useBean id="id" beanName="bn" type="type" class="class" scope="scope">

id:对象名 *

class:类  创建对象时需要完全限定名(包名+类名)

type:类型  调用对象时 * (可以用抽象父类或者接口)

scope:作用域(page * request session application)

setProperty的用法

<jsp:setProperty name="name" property="property" value="value">

name:useBean 的id

property:属性名(要注意必须跟实体类中的属性名保持一致)

value:属性值


jsp标准标签的使用

用户类  User.java

package com.pojo;

public class User {
	private int userid;
	private String username;
	private String userpwd;
	public int getUserid() {
		return userid;
	}
	public void setUserid(int userid) {
		this.userid = userid;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getUserpwd() {
		return userpwd;
	}
	public void setUserpwd(String userpwd) {
		this.userpwd = userpwd;
	}
	@Override
	public String toString() {
		return "User [userid=" + userid + ", username=" + username + ", userpwd=" + userpwd + "]";
	}
	public User(int userid, String username, String userpwd) {
		super();
		this.userid = userid;
		this.username = username;
		this.userpwd = userpwd;
	}
	public User() {
		// TODO Auto-generated constructor stub
	}
}

 登录界面  login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>login</title>
</head>
<body>
	<h1>登录界面</h1>
	<jsp:include page="index.jsp">
		<jsp:param value="1" name="type"/>
		
	</jsp:include>
	<jsp:include page="index.jsp">
		<jsp:param value="2" name="type"/>
	</jsp:include>
	<jsp:include page="index.jsp">
		<jsp:param value="3" name="type"/>
	</jsp:include>
	<!-- u即是定义了一个名为u的变量,class是这个变量的类型 -->
	<jsp:useBean id='u' class='com.pojo.User'></jsp:useBean>
	<!-- setProperty意为设置属性,这里相当于给对象u设置了username属性,值是sa,等价于java代码中的u.setUsername("sa"); -->
	<jsp:setProperty property="username" name="u" value="sa"/>
	<!-- getProperty意为得到属性,得到对象u中的username属性 -->
	<jsp:getProperty property="username" name="u"/>
	<form action="index.jsp">
		<div><input type="text" name="username"></div>
		<div><input type="text" name="password"></div>
		<button type="submit">登录</button>
	</form>
<%out.println(u.toString()); %>
</body>
</html>

主页  index.jsp 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>index</title>

	<style type="text/css">
		.h{
			border: 10px solid red;
			height: 150px;
			weith:100px;
		}
	</style>
	
</head>
<body>
	<% 	String title="";
		String type=request.getParameter("type");
		if("1".equals(type)){
			title="一号标签";
		}if("2".equals(type)){
			title="二号标签";
		}if("3".equals(type)){
			title="三号标签";
		}
	%>
	<h1 class="h"><%=title %></h1>
</body>
</html>

 


你要尽全力保护你的梦想。那些嘲笑你梦想的人,他们注定失败,他们想把你变成和他们一样。我坚信,只要心中有梦想,我就会与众不同。你也是。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值