Jsp基础个人学习摘要

1. Jsp 注释
<%-- Jsp注释部分 --%>
而HTML中注释<!-- Html注释部分 -->
注:Jsp注释不会被发送到客户端。

2. Jsp声明
<%! 声明部分 %>
Jsp声明用于声明变量和方法,最终将会转换成对应Servlet的成员变量或成员方法。

3. 输出Jsp表达式
<%=表达式 %>

4. Jsp脚本
<%
...java代码...
%>
注:Jsp脚本里不能定义方法。

5. Jsp的3个编译指令
page/include/taglib
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>

<%@ include file="relativeURLSpec" %>

注:如果被嵌入的文件经常需要改变,建议使用<jsp:include >操作指令,它是动态的include语句。二者之间的区别:一)静态导入是将被导入页面的代码完全融入,两个页面融合成一个整体Servlet;而动态导入<jsp:include>则是在Servlet中使用include方法来引入页面的内容。 二)静态导入时被导入页面的编译指令会起作用;而动态导入时被导入页面的编译指令会失去作用,只是插入被导入页面的body内容。 三)动态包含还可以增加额外的参数,如:
	<jsp:include page="forward-result.jsp">
<jsp:param value="age" name="20"/>
</jsp:include>


6. Jsp的7个动作指令
jsp:forward、 jsp:param、 jsp:include、 jsp:plugin、 jsp:useBean、 jsp:setProperty、 jsp:getProperty
forward动作指令转发用户请求:
	<jsp:forward page="forward-result.jsp">
<jsp:param value="age" name="20"/>
</jsp:forward>

获取forward动作指令请求的参数:
<%=request.getParameter("age") %>

注:执行forward指令转发请求时,地址栏地址依然没有发生改变,也可用表单提交请求参数,如:
	<form id="login" method="post" action="jsp-forward.jsp">
<input type="text" name="username" />
<input type="submit" value="login" />
</form>

useBean、setProperty、getProperty语法格式:
	<jsp:useBean id="name" class="classname" scope="page|request|session|application"></jsp:useBean>
<jsp:setProperty property="BeanName" name="propertyName" value="value"/>
<jsp:getProperty property="BeanName" name="propertyName"/>


7. Jsp脚本中的9个内置对象
request、response、session、application、exception、out、page、pageContext、config
	<% 
request.setAttribute("String attributeName","Object attributeValue");
request.getAttribute("String attributeName");
request.getParameter("String parameterName");
request.getParameterValues("String parameterName");
request.setCharacterEncoding("String characterEncoding");

response.sendRedirect("pageName");
response.getOutputStream();

session.setAttribute("String attributeName","Object attributeValue");
session.getAttribute("String attributeName");

application.setAttribute("String attributeName","Object attributeValue");
application.getAttribute("String attributeName");
application.getInitParameter("String attributeName");

exception.getMessage();
exception.getStackTrace();

out.print("data");
out.println();

//page代表该页面本身,通常没有太大用处。

pageContext.getServletContext();
pageContext.getServletConfig();
pageContext.getSession();

config.getInitParameter("String initParameterName");
config.getInitParameterNames();
//config对象更多的在servlet中有效,Jsp页面通常无需配置,也就不存在配置信息。

%>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值