欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Java request对象

程序员文章站 2022-06-11 15:46:52
...

Java request对象

index1.jsp

<%@ 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 'index1.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>
    This is my JSP page. <br>
    <form action="index.jsp" method="get">
    	用户名:<input name="name" alt="abc">
    	密码:<input name="psd">
    	<input type="submit" value="提交">
    </form>
  </body>
</html>

index.jsp

<%@ 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 'index.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>
    This is my JSP page. <br>
    <a>我的第一个页面!!!</a>
    <% out.print(request.getParameter("name"));
    	out.print(request.getParameter("psd"));
    	
    	request.setAttribute("lk", "李凯");
    	out.print(request.getAttribute("lk").toString());
     %>
     <br>
     <!-- 只执行一次 -->
  	<%!int i=0; %>
     服务主机名:<%=request.getServerName() %><br>
     端口号:<%=request.getServerPort() %><br>
  ip地址:<%=request.getRemoteAddr() %><br>
  请求的主机名:<%=request.getRemoteHost() %>
    返回请求协议:<%=request.getProtocol() %>
    <%i=i+1; %>
   访问次数: <%=i %>
     
  </body>
</html>

Java request对象

Java request对象

 

相关标签: Java