Help is available for each task, or you can go straight to
the solution source code.
Task 1
Add a line of code to the template ServletParameterTest.java
file to set the OutputStream type to HTML.
Use the
setContentType()
method:
res.setContentType("text/html");
Task 2
Get the name and position parameters from the client.
Use the
getParameter()
method:
paramName = req.getParameter("name" );
paramPosition = req.getParameter("position");
Task 3
Get a handle to the OutputStream going back to the client so
that it can be used to write the HTML data back to the browser.
Use the
getOutputStream() method or the getWriter()
method:
out = res.getOutputStream();
Task 4
Compile the servlet.
javac *.java
Task 5
Install the servlet in either the JWS or use the servletrunner
to host.
See the previous Magercises for the
JWS or
servletrunner
details.
A batch file copyit is included with the solution to help copy
the class file to the Java Web Server.
Task 6
Request the service from a browser by clicking
here
for the JWS or
here
for the servletrunner.
Enter the URL
http://localhost:8080/servlet/ServletParameterTest
and observe the display in the browser.
Task 7
Request the service with the parameters Randy and
Software Mage from a browser by clicking
here
for the JWS or
here
for the servletrunner.
Enter the following URL on one line:
http://localhost:8080/servlet/ServletParameterTest?
name=Randy&position=Software%20Mage
and observe the display in the browser.
Copyright © 1998 MageLang
Institute.
All Rights Reserved.