Retrieving The Data Posted To A JSP File From HTML File
Retrieving The Data Posted To A JSP File From HTML File
Now I will show you how to retrieve the data posted from a HTML file in a JSP page. Consider an html page that prompts the user to enter his/her name, let's call it getname.htm. Here is the code of the html file <html> <head> <title>Enter your name</title> </head> <body> <p> </p> <form method="POST" action="showname.jsp"> <p><font color="#800000" size="5">Enter your name:</font><input type="text" name="username" size="20"></p> <p><input type="submit" value="Submit" name="B1"></p> </form> </body> </html> The target of form is "showname.jsp", which displays the name entered by the user. To retrieve the value entered by the user we uses the request.getParameter("username"); code. Here is the code of "showname.jsp" file: <%@page contentType="text/html" %> <!-http://www.roseindia.net/jsp --> <html> <body> <p><font size="6">Welcome : <%=request.getParameter("username") %></font></p> </body>
</html>
JSP FUNDAMENTALS
JSP page is built using components such as :
Directives :
Listing some of them to start off : 1) Page Syntax : < %@ page Language=Java extends=<Class name> import=<class> or
<package> %>
Attributes: a. Language = Java b. Import = Class c. Buffersize = d. Scope = REQUEST/PAGE/SESSION/APPLICATION e. And etc. Page directive is aimed to define certain attribute of a JSP page for e.g. Language of the page in which the page content should be written , which class to be imported so that it can be used within the JSP page. 2) Include Syntax: <%@ include file=<filename> %> Attributes: a. file = <filename> This directive is to include the a HTML, JSP or Sevlet file into a JSP file. This is a static inclusion of file i.e. it will be included into the JSP file at the time of compilation and once the JSP file is compiled any changes in the included the file will not the reflected.
Declarations:
Scriplets:
Syntax: <% All your scripts will come here %>
Expressions: