Please send questions to st10@humboldt.edu .

Random notes for CIS 480 - Advanced Java Programming, Week 15, 5-7-01

*   a next series of servlet examples:

*   (modified from Gittleman, "Internet Applications with the Java 2
Platform", pp. 159-195)
*   quotes from this are indicated by [1] below;

*   first: st10GetOrder.java: echoes back a user's order (as set in
an Order parameter)
        *   looks a lot like our examples from last time ---
	a simple doGet() method, sees if an Order parameter
	has been set, echoes back either the Order or
	"nothing, please"

	*   (cute touch: even if Order not null, but is the
	empty String when white space is trim()'d, it still echoes
	back "nothing, please")

	*   how we ran last time:

http://sorrel.humboldt.edu:8895/jservf/st10/480jlect15/st10GetOrder

		*   (note the "nothing, please")

	*   or, with an Order:

http://sorrel.humboldt.edu:8895/jservf/st10/480jlect15/st10GetOrder?Order=Ham+and+Cheese

**********
*   simple twist #1: you may very well already know how to set up
a simple HTML form with a GET request. BUT, if you do not, that's
ANOTHER way to call this servlet:     
**********
	*   see st10GetOrder.html

	*   (yeah, yeah, I know, I don't need the st10 there...)

	*   I put it into ~st10/public_html/cis480j, and ran it 
	"normally":

http://www.humboldt.edu/~st10/cis480j/st10GetOrder.html

	*   here's the pertinent HTML:

<form action = "http://sorrel.humboldt.edu:8895/jservf/st10/480jlect15/st10GetOrder" method=GET>
   Order: <input type=text name=Order size=20>
</form>

*********
*   simple twist #2: Let's ([1], pp. 166-167) "...allow the user to
submit an order either with a GET or POST request."
********

	*   see st10PostOrGetOrder.java

	*   same doGet() method!

	*   doPost() here simply [1] "delegate[s] any POST requests
	to the goGet() method":

	public void doPost(HttpServletRequest req, HttpServletResponse resp)
                          throws ServletException, IOException 
	{
		doGet(req, resp);
	}	

	*   why bother? from [1], p. 167:
	one advantage: "browser does not include the data with 
	the POST request. Thus using POST instead of GET is essential 
	to keep the data sent private. Data sent with a GET request is 
	appended to the URL and displayed in the browser's address 
	field."

	*   copy st10GetOrder.html to st10PostOrGetOrder.html --- and
	change the servlet name (to st10PostOrGetOrder), and change 
	the method to POST;

	*   now, when you enter something into:

http://www.humboldt.edu/~st10/cis480j/st10PostOrGetOrder.html
	
	...note that you do NOT see ?Order in resulting URL;

*********
*   simple twist #3: allow a more-detailed order for an ice-cream
sundae...
********

*   st10PostOrder.java, st10PostOrder.html

*   note the HTML analogues to Java GUI components...

********
*   a few odds and ends, to conclude
********

*   SSI: server-side includes
        *   can specify files on server-side to include --- presumably
	these could be large chunks of HTML...?

*   JSP: Java server pages
        *   HTML with special <% %> tags --- they are on the
	server-side, and are *compiled* into servlets

(notes from last lecture's posted notes, but not really discussed then...)
*   from [6]: So, what is JSP and how does THAT fit in here?

        *   "JSP is a dynamic scripting capability for web pages that
            allows Java as well as a few special tags to be embedded
            into a web file (HTML/XML, etc).

        *   The suffix traditionally ends with .jsp to indicate to the
            web server that the file is a JSP file.

        *   JSP is a server side technology - you can't do any client
            side validation with it.

        *   JSP files actually get compiled into Servlets, so what is
            the point? Why not just write Servlets?

                *   For most people, the benefit is twofold:

                        *   The focus is on HTML.

                        *   Java and the JSP extensions assist in making
                        the HTML more functional.

                        *   Servlets on the other hand allow outputting
                        of HTML but it is a tedious process.

                        *   It is easy to make a change and then let the
                            JSP capability of the Web Server you are
                            using deal with compiling it into a
                            Servlet and running it.

*   I have read the opinion that JSP can replace server-side 
includes (SSI's) --- IF your web server supports JSP...