zoukankan      html  css  js  c++  java
  • JSP之request对象



    //req.jsp
    <%@ page language="java" import="java.util.*" contentType="text/html; charset=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 'req.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>
        <form name="reqForm" action="registe.jsp" method="post">
        	<table>
        		<tr>
        			<td>用户名</td>
        			<td><input type="text" name="username"/></td>
        		</tr>
        		<tr>
        			<td>爱好</td>
        			<td>
    	    			<input type="checkbox" name="favorite" value="read"/>读书
    	    			<input type="checkbox" name="favorite" value="run"/>跑步
    	    			<input type="checkbox" name="favorite" value="Internet"/>上网
        			</td>
        		</tr>
        		<tr>
        			<td colspan="3"><input type="submit" value="登陆"></td>
        		</tr>
        	</table>
        	<br/>
        	<br/>
        	<a href="registe.jsp?

    username=张三">注冊</a> </form> </body> </html>

    //registe.jsp
    <%@ page language="java" import="java.util.*" contentType="text/html; charset=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 'registe.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>
          <%
              request.setCharacterEncoding("utf-8");//解决中文提交后的乱码问题,但不能解决URL链接过来的中文乱码问题
              request.setAttribute("password", "123456");
          %>
        <%=request.getParameter("username") %>
        <%
            if(request.getParameterValues("favorite") != null){
                String[] favorites = request.getParameterValues("favorite");            
                for(int i=0;i<favorites.length;i++){
                    out.println(favorites[i]+"&nbsp;&nbsp;");
                }
            }        
        %><br/>
        <%=request.getAttribute("password") %><br/>
        <%=request.getCharacterEncoding() %><br/>
        请求体的MIME类型:<%=request.getContentType() %><br>
        请求的协议类型及其版本:<%=request.getProtocol() %><br>
        返回接受请求的server主机名:<%=request.getServerName() %><br/>
        返回server接受此请求所用的端口号:<%=request.getServerPort() %><br/>
        返回请求体的长度:<%=request.getContentLength() %><br/>
        返回请求的clientIP:<%=request.getRemoteAddr() %><br>
        返回一虚拟路径的真实路径:<%=request.getRealPath("registe.jsp") %><br/>
        返回上下文路径:<%=request.getContextPath() %>
      </body>
    </html>
    
    

    <Connector port="8888" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443" URIEncoding="utf-8" />






  • 相关阅读:
    一些遇到的错误的总结:
    ThinkPHP add save delete的返回说明
    一些实用函数 :去除html标签//去除空白//截取汉字
    group_concat
    linux环境下使用mkdir()函数无法创建目录的问题
    报错:Namespace declaration statement has to be the very first statement in the script的解决方法
    ThinkPHP中,字段更新加1的几种写法
    小狼毫输入法安装与简单配置(windows系统)
    对win10和win11的吐嘈
    看死亡诗社时有的一点新想法
  • 原文地址:https://www.cnblogs.com/llguanli/p/8778134.html
Copyright © 2011-2022 走看看