I have a jsp
with a text field. I want to print out the text I inserted into text field, but have no idea how to do it.
JSP page:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Return the name</title>
</head>
<body>
<h1>Welcome</h1>
Insert your text here:<br>
<form name="txtForm" action="Main.java" method="post">
<input type="text" name="txt">
<input type="submit" value="Send">
</form>
</body>
</html>
And this is the class(Main.java)
that is handling the JSP:
public class Main extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String text = request.getParameter("txt");
Date d = new Date();
System.out.println("The name you enter is:" + text + "at the time : " + d);
}
}
What I want is to take the info from the jsp through my class then print it out back on a the jsp. How can this be done? I tried to use <%@ import ... >
and coudn't make it work. :(
Thank you.