Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174

Deprecated: Function split() is deprecated in /home3/vvaswani/public_html/community/columns/trog/article.php on line 101

Deprecated: Function eregi_replace() is deprecated in /home3/vvaswani/sql.php on line 301

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home3/vvaswani/public_html/community/columns/trog/article.php on line 107

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home3/vvaswani/public_html/community/columns/trog/article.php on line 109

Deprecated: Function ereg_replace() is deprecated in /home3/vvaswani/public_html/community/columns/trog/article.php on line 124

Deprecated: Function ereg_replace() is deprecated in /home3/vvaswani/public_html/community/columns/trog/article.php on line 125

Deprecated: Function split() is deprecated in /home3/vvaswani/public_html/community/columns/trog/article.php on line 127

Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174

Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174

Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174

Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174

Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174

Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174

Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174

Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174

Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174

Deprecated: Function ereg() is deprecated in /home3/vvaswani/db-mysql.php on line 174
The Melonfire Community - Trog
Logo         Community
  Trog
Services
The Company
Community
Columns
Your Account
Contact Us
 
 
The JSP Files (part 4): The Red Pill
Find out JSP can be used to process form data, and learn about the Request object.

| Entering The Matrix |

Once the form has been submitted, the script "matrix.jsp" is called upon to parse the date entered into the form. At this point, the script simply reads the name entered into the form, and displays a message containing that name; however, at a later point, it will be modified to grant or deny access based on the name entered.


<html>
<head>
<basefont face="Arial">
</head>

<body>
<center>
<%
// matrix.jsp

// define the variables used in the scriptlet
String fname;

// assign values
fname = request.getParameter("name");

// print the details
out.println("Welcome to The Matrix, " + fname + "!");

%>
</center>
</body>
</html>


And now, if you enter some data into the form (say, "joe"), this is what you should see:


Welcome to The Matrix, joe!


An explanation is in order here. As always, the first step is to define the variables that will be used throughout the script - in this case, the variable "fname".


<%
// define the variables used in the scriptlet
String fname;
%>


Next, the value of the form variable "name" has to be assigned to the JSP variable "fname" - this is accomplished with the getParameter() method, which accepts a variable name as parameter and returns the variable value.

The getParameter() method actually belongs to a JSP object called the Request object; unlike many other objects in JSP, the Request object is an "implicit" object, so called because you do not need to explicitly create an instance of the object when you want to use it. The getParameter() method is just one of many methods available in this object, and we'll be exploring some of the others as well in this tutorial.

Once the value of a form variable has been assigned to a JSP variable, it can be treated in exactly the same manner as other JSP variables. In the example above, a println() function call takes care of printing the welcome string, with the name incorporated into it.

You can also use the POST method (which offers greater security and reliability) to process form data - simply alter the HTML form so that the METHOD used is POST.


<form method="POST" action="matrix.jsp">

...

</form>


The script "matrix.jsp" will continue to function as advertised without requiring any changes. Thus, the getParameters() method can be used to access form variables regardless of the method used to post the data.

And you can add a simple conditional statement to deny access to all but the most favoured:


<html>
<head>
<basefont face="Arial">
</head>

<body>
<center>
<%
// matrix.jsp

// define the variables used in the scriptlet
String fname;

// assign values
fname = request.getParameter("name");

// print the details
if (fname.equals("neo"))
{
out.println("Welcome to The Matrix, Neo!");
}
else
{
out.println("Leave immediately, Agent!");
}
%>
</center>
</body>
</html>



How to do Everything with PHP & MySQL
How to do Everything with PHP & MySQL, the best-selling book by Melonfire, explains how to take full advantage of PHP's built-in support for MySQL and link the results of database queries to Web pages. You'll get full details on PHP programming and MySQL database development, and then you'll learn to use these two cutting-edge technologies together. Easy-to-follow sample applications include a PHP online shopping cart, a MySQL order tracking system, and a PHP/MySQL news publishing system.

Read more, or grab your copy now!


previous page more like this  print this article  next page
 
Search...
 
In trog...
Logging With PHP
Building A Quick-And-Dirty PHP/MySQL Publishing System
Output Buffering With PHP
Date/Time Processing With PHP
Creating Web Calendars With The PEAR Calendar Class
more...
 
In the hitg report...
Crime Scenes
Animal Attraction
Lord Of The Strings
more...
 
In boombox...
Patience - George Michael
Think Tank - Blur
My Private Nation - Train
more...
 
In colophon...
Hostage - Robert Crais
The Dead Heart - Douglas Kennedy
Right As Rain - George Pelecanos
more...
 
In cut!...
American Chai
The Core
Possession
more...
 
Find out how you can use this article on your own Web site!


Copyright © 1998-
Strict Standards: mktime(): You should be using the time() function instead in /home3/vvaswani/public_html/community/columns/trog/article.php on line 731
2018 Melonfire. All rights reserved
Terms and Conditions | Feedback