初学jsp

主页面:

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

<%
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 'AboutPages' 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>
    <form action="" method="get" >
        输入一个值:
        <input type="text" name="myInput" />
        <input type="submit" value="提交" /> 
    </form>
    <%

        //如何获取表单上的值
        String strValue = request.getParameter("myInput");
        byte c[] = strValue.getBytes("ISO-8859-1");
        strValue = new String(c,"UTF-8");
        if(null != strValue)
        {
            out.print("the value you input is " + strValue);
        }
     %>

     <!-- 引入其他文件的代码 -->
     <%@ include file="somehtml.html" %>


     <br/>
     of course maybe I can import the file like this:
     <jsp:include page="counter.jsp" >

        <!-- 引用其他页面的代码,可以设置参数 -->
         <jsp:param name="Times" value="10" />
     </jsp:include>
  </body>
</html>

 

 

somehtml.html:

<div style="width:100px;height:100px;background-color:red;" >
    what the hell are you talking about?
</div>
<% out.print("Of Course,I wanna know weither jsp Code is Supported too!"); %>

 

 

counter.jsp

<%

    //获取引用本文件时,设置的参数
    String strTimes = request.getParameter("Times");
    int intTimes = Integer.parseInt(strTimes);
    for(int i = 1;i <= intTimes;i ++)
    {
        out.print("<br/>this is the " + i + " time");
    }
%>

posted on 2011-09-26 17:44  冰危节奏  阅读(124)  评论(0)    收藏  举报

导航