request.getParameter(String arg0) gets a null string or an empty string analysis

1.request.getParameter(String arg0) gets null string
1). The parameter does not match the attribute value of the name attribute
2). The parameter matches the attribute value of id attribute without setting the attribute value of name attribute
3). The corresponding parameter value is not passed through POST/GET
4). Does not match the parameter in the URL

2.request.getParameter(String arg0) gets that the string is empty
1). Submit that the attribute value of the value attribute is "";


Run the following JSP code and it should be understood soon:

<%@ 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>
    <form action="" method="post">
    <input type="text" value="" name="ts" id="tsId"><br>
    <input type="submit" value="Submission">
    </form>
     <a href="index.jsp?tsURL=I am URL Tips in">Jump</a><br>
    	//Tips:
    <%	
    	String ts = request.getParameter("ts");
    	if(ts==null){
    		out.print("I am Null!");
    	}else if(ts.equals("")){
    		out.print("I'm an empty string!");
    	}else{
    		out.print(ts);
    	}
    	out.print("<br>");
    	if(request.getParameter("tsURL")!=null){
    		out.print(request.getParameter("tsURL"));
    	}
    	
    	/**
    	1.request.getParameter(String arg0)Get string is empty
    		1).Parameter does not match property value of name property
    		2).Parameter matches property value of id property without setting property value of name property
    		3).The corresponding parameter value is not passed through POST/GET
    		4).Does not match the parameter in the URL
    	2.request.getParameter(String arg0)Get string as empty string
    		1).Commit is that the property value of the value property is "";
    	**/
     %>
  </body>
</html>

When I just came in, I didn't pass the parameter value through POST/GET, so I was Null at the beginning!

When nothing is submitted in the input box, an empty string is obtained, because the default property value of the value property is "", which shows that I am an empty string

After that, when you add some information to the input box, it will be printed intact

After clicking the jump button, you will get the parameter value in the URL. At the bottom, print the prompt that I am in the URL

 

 

Tags: Attribute JSP Java

Posted on Sun, 05 Jan 2020 18:56:50 -0800 by evilcoder