posts - 165, comments - 198, trackbacks - 0, articles - 1
            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          EL 標(biāo)簽小例

          Posted on 2007-08-02 10:13 G_G 閱讀(1619) 評(píng)論(3)  編輯  收藏 所屬分類: JspTag
          問(wèn)題: jsp 的簡(jiǎn)化與 統(tǒng)一性
          解決: EL 標(biāo)簽

          jsp.頁(yè)面

          <%@?taglib?prefix="fn"?uri="/WEB-INF/fn.tld"?%>
          <%@?taglib?prefix="c"?uri="/WEB-INF/c-1_0-rt.tld"?%>
          <%@?taglib?prefix="x"?uri="/WEB-INF/x-1_0-rt.tld"?%>
          <%@?page?isELIgnored="false" %>
          <%@?page?language="java"?import="java.util.*"?pageEncoding="UTF-8"%>


          <%
          String?
          path?=?request.getContextPath();
          String?basePath?=?request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
          %>

          <!DOCTYPE?HTML?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN">
          <html>
          ??
          <head>
          ????
          <base?href="<%=basePath%>">
          ????
          ????
          <title>My?JSP?'MyJsp.jsp'?starting?page</title>
          ????
          ????
          <meta?http-equiv="pragma"?content="no-cache">
          ????
          <meta?http-equiv="cache-control"?content="no-cache">
          ????
          <meta?http-equiv="expires"?content="0">
          ????
          <meta?http-equiv="keywords"?content="keyword1,keyword2,keyword3">
          ????
          <meta?http-equiv="description"?content="This?is?my?page">
          ????
          ????
          <!--
          ????<link?rel="stylesheet"?type="text/css"?href="styles.css">
          ????
          -->
          ??
          </head>
          ??
          ??
          <body>
          ????
          <c:set?var="url"><%=basePath%>/xml</c:set>
          ????
          <c:import?var="xmlDoc"?url="${url}"/>
          ????
          <x:parse?xml="${xmlDoc}"?var="doc"?/> ?? ??? ??? ??? ??? ??? ??? ??? ???? //xml解析
          ????
          <c:set?var="bookName"?><x:out?select="$doc/xml-body/books/book[@id='1']"/></c:set> ? //xml 定位
          ????${fn:substring(bookName,"0",?fn:length(bookName)-2?)?}<br> ????????????????????????? //字符substring

          ???? <x:forEach var="item" select="$doc/xml-body/books/book"? >?????? //迭帶
          ??? ??? <x:out select="$item" /><br>
          ???? </x:forEach>

          ???
          ??
          </body>
          </html>


          結(jié)果得到是:?? book1_goog
          ??? ?? ???? book1_google
          ??? ??? ??? book2_baidu
          ??? ??? ??? book3_tiancai

          /xml 路徑是

          package?Servlet;

          import?java.io.IOException;
          import?java.io.PrintWriter;

          import?javax.servlet.ServletException;
          import?javax.servlet.http.HttpServlet;
          import?javax.servlet.http.HttpServletRequest;
          import?javax.servlet.http.HttpServletResponse;

          public?class?XmlServlet?extends?HttpServlet?{
          ????
          /**
          ?????*?
          ?????
          */
          ????
          private?static?final?String?CONTENT_TYPE?=?"text/html;?charset=GBK";
          ????
          public?void?init()?throws?ServletException{}
          ????
          public?void?doGet(?????HttpServletRequest?request,
          ????????????????????????HttpServletResponse?response?)
          ????????????????????????
          throws?ServletException,IOException{
          ????????PrintWriter?out?
          =?response.getWriter();
          ????????
          ????????response.setContentType(CONTENT_TYPE);
          ????????response.setCharacterEncoding(
          "GBK");
          ????????
          ????????
          ????????out.print(
          "<?xml?version='1.0'?encoding='UTF-8'?>");
          ????????out.print(
          "<xml-body>");
          ????????????????out.print(
          "<name>RW</name>");
          ????????????????out.print(
          "<passWord>123456</passWord>");
          ????????????????out.print(
          "<age>28</age>");
          ????????????????out.print(
          "<books>");
          ????????????????????????out.print(
          "<book?id='1'>book1_google</book>");? //jsp 定位得到的? 字符
          ????????????????????????out.print(
          "<book?id='2'>book2_baidu</book>");
          ????????????????????????out.print(
          "<book?id='3'>book3_tiancai</book>");
          ????????????????????????out.print(
          "</books>");
          ????????out.print(
          "</xml-body>");????????
          ????}
          ????
          public?void?doPost(?HttpServletRequest?request,
          ????????????????????????HttpServletResponse?response?)
          ????????????????????????
          throws?ServletException,IOException{
          ????????doGet(request,response);
          ????}
          }

          心得:寫EL心情 就是好


          評(píng)論

          # re: EL 標(biāo)簽小例   回復(fù)  更多評(píng)論   

          2007-08-02 10:14 by G_G
          自己沙發(fā)下

          # re: EL 標(biāo)簽小例   回復(fù)  更多評(píng)論   

          2009-08-21 14:49 by 大范甘迪
          你寫這個(gè)的作用是什么??????????

          # re: EL 標(biāo)簽小例   回復(fù)  更多評(píng)論   

          2009-09-22 15:56 by czk
          el標(biāo)簽作用用于取值和附值
          主站蜘蛛池模板: 施甸县| 香港| 丹棱县| 沛县| 孟津县| 涞源县| 乌拉特中旗| 彰化县| 英吉沙县| 苗栗县| 资源县| 子洲县| 六枝特区| 航空| 从化市| 高唐县| 伊宁市| 蓝山县| 鄢陵县| 丰原市| 洛宁县| 洛隆县| 建阳市| 保靖县| 顺义区| 淳安县| 岳阳县| 孟连| 买车| 兴和县| 苍南县| 崇义县| 平南县| 聂荣县| 南郑县| 蓝山县| 虞城县| 安庆市| 都兰县| 清新县| 张家界市|