How to set input field value in Jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <html> <form action="index.jsp"> <body> First INPUT: <input name="firstinput" type="text" value=<%=request.getParameter("firstinput") %>> <br> <input type="submit" value="Submit"> <% String first = request.getParameter("firstinput"); out.println(first); %> </body> </form> </html> 

Ths is my code when Put Input tax, after Button presses its set on tax and tax with stamp, but when I enter tax "tax", then the value is set as tax in the input field, and Print is correct "tax " I want to set the input field the value is also β€œtax”, when I take the input β€œtax” after clicking, please help

+6
source share
2 answers

You have both options:

 name="firstinput" 

and

 name="fname" 

for the same input field!

UPDATE: In addition to this, change:

 value=<%=request.getParameter("firstinput") %>> 

in

 value='<%=request.getParameter("firstinput")%>' /> 
+7
source

His working slim dude

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <form action="index.jsp" method="get"> First INPUT: <input name="firstinput" type="text" value=<%=request.getParameter("firstinput") %>> <br> <input type="submit" value="Submit"> <% String first = request.getParameter("firstinput"); out.println(first); %> </form> </body> </html> 
+1
source

Source: https://habr.com/ru/post/951447/


All Articles