制作微信公众号网站开发,海南做网站的公司,星沙做淘宝店铺网站,品牌形象推广1.page指令#xff1a;描述页面信息 pageENcoding:软件编码
contentType#xff1a;浏览器编码
2.include指令#xff1a;将多个网页合成一个网页#xff0c;静态包含网页
问题#xff1a;1.在网页源代码中#xff0c;会形成错误的多遍代码#xff0c;将主页面代码和…1.page指令描述页面信息 pageENcoding:软件编码
contentType浏览器编码
2.include指令将多个网页合成一个网页静态包含网页
问题1.在网页源代码中会形成错误的多遍代码将主页面代码和副页面各删除一半。 2.多个网页中的代码不能有任何冲突
% page languagejava contentTypetext/html; charsetUTF-8pageEncodingUTF-8%
!DOCTYPE html
% include file NewFile.jsp %h3这位是一个主网页1/h3
h3这是另一个网页的变量%a %/h3
/body
/html
% page languagejava contentTypetext/html; charsetUTF-8pageEncodingUTF-8%
!DOCTYPE html
html
head
meta charsetUTF-8
titleInsert title here/title
/head
body
h3这是一个导航栏/h3
h3% int a12;%/h3 查看网页源代码 完整代码 3.include动作
jsp动作:include,param,forward
基本语法:
1.jsp:include page/
2.jsp:include page
包含网页传递数据
include指令静态包含,代码复用一起生成网页
注意被包含网页不需要写部分网页代码一起编译执行运行1次运行效率高
include动作动态包含结果复用共同生成网页
注意被包含网页不需要写结构网页代码一起编译执行运行多次运行效率低 % page languagejava contentTypetext/html; charsetUTF-8pageEncodingUTF-8%
!DOCTYPE html
html
head
meta charsetUTF-8
titleInsert title here/title
/head
body
jsp:include pageNewFile1.jsp/
h3这是一个网页1/h3
/body
/html% page languagejava contentTypetext/html; charsetUTF-8pageEncodingUTF-8%
!DOCTYPE htmlh3次级网页/h34.param动作
param动作向其他网页传递数据
用法jsp:param value值 name值对应的名字
注意事项动作不能单独使用要和其他动作一起使用
% page languagejava contentTypetext/html; charsetUTF-8pageEncodingUTF-8%
!DOCTYPE html
html
head
meta charsetUTF-8
titleInsert title here/title
/head
body
jsp:include pageNewFile1.jsp
jsp:param value18 nameage/
/jsp:include
h3这是一个网页1/h3
/body
/html
% page languagejava contentTypetext/html; charsetUTF-8pageEncodingUTF-8%
!DOCTYPE htmlh3次级网页/h3
%String s request.getParameter(age);out.print(s);%
传递中文乱码:数据传输和数据接收编码
解决方法在发送和接收的网页中添加%request.setCharacterEncoding(UTF-8);%
% page languagejava contentTypetext/html; charsetUTF-8pageEncodingUTF-8%
!DOCTYPE html
html
head
meta charsetUTF-8
titleInsert title here/title
/head
body%request.setCharacterEncoding(UTF-8);%
jsp:include pageNewFile1.jsp
jsp:param value12 nameid1/
jsp:param value12.34 nameid2/
jsp:param value张红 nameid3/
/jsp:include
h3这是一个网页1/h3
/body
/html
% page languagejava contentTypetext/html; charsetUTF-8pageEncodingUTF-8%
!DOCTYPE htmlh3次级网页/h3
%request.setCharacterEncoding(UTF-8);String s request.getParameter(id1);String s1 request.getParameter(id2);String s2 request.getParameter(id3);Double b Double.parseDouble(s1)10;//把s字符串转换为double类型Integer iInteger.parseInt(s)10;//首字母大写是类名String s5b ;out.print(s);out.print(s1);out.print(s2);
% forward:跳转到新页面
跳转到新页面
语法1.jsp:forward page“relativeURL”不用传参数
2.jsp:forward page要转向的页面
使用param动作传递数据
jsp:param name paramterName value parametrValue /传参数
/jsp:forward
注意用forward跳转后的页面显示的网址是跳转之前的网页
执行forward代码后不在执行
% page languagejava contentTypetext/html; charsetUTF-8pageEncodingUTF-8%
!DOCTYPE html
html
head
meta charsetUTF-8
titleInsert title here/title
/head
bodyh3这是主页面/h3%-- jsp:forward pageNewFile1.jsp/ --%%request.setCharacterEncoding(UTF-8);%jsp:forward pageNewFile1.jsp jsp:param name 张三 value name //jsp:forward % request.setAttribute(id, 18); %/body
/html% page languagejava contentTypetext/html; charsetUTF-8pageEncodingUTF-8%
!DOCTYPE html
html
head
meta charsetUTF-8
titleInsert title here/title
/head
body%request.setCharacterEncoding(UTF-8); % h3这是跳转网页/h3%String s request.getParameter(name);%%out.print(request.getAttribute(id));%h3登录成功欢迎/h3
/body
/html % page languagejava contentTypetext/html; charsetUTF-8pageEncodingUTF-8%
!DOCTYPE html
html
head
meta charsetUTF-8
titleInsert title here/title
/head
bodyh3这是主页面/h3%-- jsp:forward pageNewFile1.jsp/ --%%request.setCharacterEncoding(UTF-8);%% request.setAttribute(id, 18); %jsp:forward pageNewFile1.jsp jsp:param name 张三 value name //jsp:forward /body
/html