JSP web应用程序开发教程实验一

版权声明:转载请注明出处:http://blog.csdn.net/dajitui2024 https://blog.csdn.net/dajitui2024/article/details/79396232

编码统一utf-8

文件名:a.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>  
<html>  
  <head>  
  </head>  
  <body>  
    <%  
        int num = Integer.parseInt(request.getParameter("num"));  
        out.println(num+"的平方是:"+num*num);  
     %>  
  </body>  
</html>  

文件名:b.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>  
<html>  
  <head>  
  </head>  
  <body>  
     <jsp:include page="a.jsp">  
        <jsp:param value="19" name="num"/>  
     </jsp:include>  
  </body>  
</html>  

文件名:ex201.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>  
<html>  
<head>  
</head>  
<body>  
    <%  
        Date date = new Date();  
        int hour = date.getHours();  
        int minute = date.getMinutes();  
        int second = date.getSeconds();  
        
        if (hour >= 0 && hour < 12) {  
            out.println("早上好!");  

        } else if (hour >= 12 && hour < 19) {  
            out.println("下午好!");  
 
        
        } else {  
            out.println("晚上好!");  
       
        }  
    %>  
</body>  
</html>  

文件名:test1.jsp

<%@ page contentType="text/html;charset=utf-8" %>
<%
request.setCharacterEncoding("utf-8");
String strUserName = "";
strUserName = (String)request.getParameter("UserID");
if(strUserName.equals("张三")){
    out.println("你好" + strUserName);
}else{
    out.println("名称错误");
}

%>
<br>姓名:<%=strUserName%><br>

文件名:test2.jsp

<%@ page contentType="text/html;charset=utf-8" %>
<html><body>
    <form action= " test1.jsp" method="post">
       <p>姓名:<input type="text" size="20" name= "UserID"></p>
    <p><input type="submit" value="提 交"> </p>
            </form>
</body></html>
上一篇:力扣 104题 二叉树的最大深度 个人题解


下一篇:LeetCode199 二叉树的右视图