jsp handles the splicing of form parameters by taking every piece of information in c for loop + get mode

Keywords: Session JSP Attribute

The results are as follows:

Click Send to get userID and input box content.

Actions are not allowed to be spliced in the form get submission way. When a get request is made, the contents of the input box are automatically spliced into the address bar, ignoring your action splicing.

So the form get submission can only pass one parameter, if you want to pass more than one parameter, for example:

Input box input + user ID clicked,

Then it needs to be passed in the form of hidden input:

<input type="hidden" name = "flag" value = "${b.getrNo()}">
<input type="text" id = "talk_input" name = "talk_input">
<input type="submit" value="Send out"></td>	
Click Send to pass two input values: xxx? Talk_input= "the value in the input box" & flag= "the userID of the click"

The code is as follows:

JSP:

		<c:forEach items="${requestScope.list}" var="b" varStatus = "i">
			<form action="sendMessageServlet" method="get">  
			<tr align="center" bgcolor="white">
			   	
				<td>${b.getrName()}</td>
				<td>${b.getRsex()}</td>
				<td>${b.getRage()}</td>
				<td>${b.getXz()}</td>				
				<td>${b.getXx()}</td>
				<td>${b.getComment()}</td>
				<td><input type="text" id = "talk_input" name = "talk_input"> 
				<input type="hidden" name = "flag" value = "${b.getrNo()}">
				<input type="submit" value="Send out"></td>	
			</tr>
			</form>
		</c:forEach>

servet:


                                        String text = req.getParameter("talk_input");//Get the attribute values in the form
					text =new String(text.getBytes("iso8859-1"),"UTF-8");//Solve the random code problem of get method.
					//String c_name = req.getParameter("c_name");
					String toUser = req.getParameter("flag");
					System.out.println(text);
					HttpSession session=req.getSession();//Returns the session associated with the current request, and if not creates one on the server side.
					String fromUser = (String) session.getAttribute("RNO");
					System.out.println(toUser+fromUser+text);






Posted by brentech on Fri, 15 Feb 2019 00:51:17 -0800