码迷,mamicode.com
首页 > Web开发 > 详细

jsp三大指令

时间:2015-07-28 18:33:53      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:javaweb

一:page指令

1.指定编码和语言

<%@ page language="java"import="java.util.*" pageEncoding="UTF-8"%>

2.指定页面的显示形式。word

<%@ page language="java"import="java.util.*" contentType="application/msword;charset=utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP ‘pageword.jsp‘ starting page</title>
  </head>
  <body>
    <table border="1">
    <!-- 这里设置一下生成的文件名 -->
    <%
      response.setHeader("Content-Disposition","attachment;filename=pageword.doc");
    %>
      <tr><td>java语言</td></tr>
      <tr><td>php语言</td></tr>
      <tr><td>c++语言</td></tr>
    </table>
  </body>
</html>

3.处理错误界面

show.jsp

<%@ page language="java" import="java.util.*"pageEncoding="UTF-8"%>
<%@ page errorPage="err.jsp" %>
<%@ taglib prefix="c"uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP ‘show.jsp‘ starting page</title>
  </head>
  <body>
    <%
      intresult=10/0;
    %>
  </body>
</html>

err.jsp

<%@ page language="java"import="java.util.*" pageEncoding="UTF-8"%>
<%@ page isErrorPage="true" %>
<%@ taglib prefix="c"uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP ‘err.jsp‘ starting page</title>
  </head>
  <body>
    <h1>程序出现了错误!</h1>
  </body>
</html>

二:包含指令

1.   静态包含:

<%@include file="" %>

include.jsp

<%@ page language="java"import="java.util.*" pageEncoding="UTF-8"%>

<%@ taglib prefix="c"uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01Transitional//EN">

<html>

  <head>

    <title>My JSP‘include.jsp‘ starting page</title>

  </head>

  <body>

    <%@includefile="Demo2.jsp" %>

  </body>

</html>

Demo2.jsp

<%@ page language="java" import="java.util.*"pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01Transitional//EN">

<html>

  <head>

    <title>My JSPDemo2</title>

  </head>

  <body>

          被包含到include.jsp界面中。

  </body>

</html>

2.动态包含

<jsp:include page="Demo2.jsp"/>

三:跳转指令

Demo2.jsp

<%@page language="java"import="java.util.*"pageEncoding="UTF-8"%>

<%@taglib prefix="c"uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPEHTML PUBLIC "-//W3C//DTDHTML 4.01 Transitional//EN">

<html>

 <head>

   <title>My JSP Demo2</title>

 </head>

 <body>

     <%

         String name="China";

     %>

      <jsp:forwardpage="forwordJsp.jsp">

         <jsp:paramvalue="<%=name%>" name="name"/>

         <jsp:paramvalue="http://blog.csdn.net/dzy21"name="info"/>

      </jsp:forward>

 </body>

</html>

forwordJsp.jsp

<%@page language="java"import="java.util.*"pageEncoding="UTF-8"%>

<%@taglib prefix="c"uri="http://java.sun.com/jsp/jstl/core"%>

 

 

<!DOCTYPEHTML PUBLIC "-//W3C//DTDHTML 4.01 Transitional//EN">

<html>

 <head>

   <title>My JSP ‘forwordJsp.jsp‘ starting page</title>

 </head>

 

 <body>

<!--接收传递过来的参数-->

   <h1>跳转后的页面</h1>

   <h2>参数一:<%=request.getParameter("name")%></h2>

   <h2>参数二:<%=request.getParameter("info")%></h2>

 </body>

</html>

 QQ:1327880701,一起学习进步交朋友。

版权声明:博主原创文章,转载请说明出处。http://blog.csdn.net/dzy21

jsp三大指令

标签:javaweb

原文地址:http://blog.csdn.net/dzy21/article/details/47108673

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!