课堂笔记
视频笔记
链接:http://pan.baidu.com/s/1c1JuK5U 密码:3614
链接:http://pan.baidu.com/s/1c1KGCTE 密码:h1dk
一.修改公司名字为变量.
1.首先在main里面设置了一个变量
<jsp:include page="footer.jsp">
<jsp:param value="北京甲骨文科技有限公司"
name="firm"/>
</jsp:include>
2.其次在footer中接收变量
<p>版权所有<%=request.getParameter("firm") %>有
限公司2000-2017</p>
看懂啥意思了吧,这个直接就OK了.
3.然后运行出现了乱码,这个要在body中加上这个
<%
request.setCharacterEncoding("UTF-8");
%>
小结:program设置变量,footer中引用,然后解决乱码问
题.
二.jsp:forward 动作元素
<%
if(request.getParameter("url")!=null)
{
%>
<jsp:forward page="hello.jsp"></jsp:forward>
<%
}
%>
<!---->这是html注释,不能放在jsp中
<%-- --%>这是jsp注释,可以放在jsp中
这两个注释在里面都会出现页面无法加载的问题
动作元素里面是不能包含注释的
三.稍微改一改,我们在uname上做文章
如果名字不为空,那么就把名字传到hello.jsp中,并且显示你好:张三(uname)
<jsp:param value="<%=request.getParameter(\"uname\") %>" name="a"/>
测试
uname不为空结果?跳转到hello.jsp并显示您好:uname
uname为空结果?还是跳转到hello.jsp,显示你好:
http://blog.youkuaiyun.com/zeephom/article/details/77905675
为什么还是能跳转过来?这个有问题啊!
原因:当<jsp:include>标签没有参数时,<jsp:include page="include/header.jsp">的配对标签</jsp:include>不能换行
else
{
%>
<jsp:forward page="second.jsp"></jsp:forward>
<%
}
%>
代码
main.jsp
<%@page import="javafx.scene.control.Alert"%>
<%@ 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>
<form action="" method="post">
地址:<input type="text" name="url"><br/>
姓名:<input type="text" name="uname"><br/>
<input type="submit" value="页面跳转">
<%
if(request.getParameter("uname")!=null && !request.getParameter("uname").equals(""))
{
System.out.println(request.getParameter("uname"));
%>
<jsp:forward page="hello.jsp">
<jsp:param value="<%=request.getParameter(\"uname\") %>" name="a"/>
</jsp:forward>
<%
}
%>
</form>
<%
request.setCharacterEncoding("UTF-8");
%>
<h1 align="center">这是主页面</h1>
<!---->
<%----%>
<jsp:include page="footer.jsp">
<jsp:param value="北京甲骨文科技有限公司" name="firm"/>
</jsp:include>
</body>
</html>
footer.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>
<%
request.setCharacterEncoding("UTF-8");
%>
<hr>
<br></br>
<p>版权所有<%=request.getParameter("firm") %>有限公司2000-2017</p>
</body>
</html>
hello.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>
<%
request.setCharacterEncoding("UTF-8");
%>
你好:<%=request.getParameter("a") %>
</body>
</html>