You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
a. [deployable examples](http://github.com/thomasWeise/distributedComputingExamples/tree/master/javaServerPages/examples)
12
16
13
17
Since I also use the same code in my slides, there are some special comments such as `//(*@\serverBox{2)}@*)` for formatting in my codes ... you can safely ignore them ^_^
Copy file name to clipboardExpand all lines: javaServerPages/examples/README.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,48 +10,48 @@ This small JSP creates a [HTML](https://en.wikipedia.org/wiki/HTML) page printin
10
10
11
11
If your application is running in GlassFish, you can access this JSP as [http://localhost:8080/myJSPs/greetings.jsp](http://localhost:8080/myJSPs/greetings.jsp).
This small JSP creates a plain text response containing the [IP address](https://en.wikipedia.org/wiki/IP_address) of the client.
18
18
19
19
If your application is running in GlassFish, you can access this JSP as [http://localhost:8080/myJSPs/printClientAddress.jsp](http://localhost:8080/myJSPs/printClientAddress.jsp).
### 1.3. Count Web Page Visits (unsynchronized): `counterUnsynchronized.jsp`
24
24
25
25
This JSP counts the number of times it was visited. It does so by creating a `long` member variable named `numVisitors`. Whenever the servlet is loaded, this variable will be incremented by one and the result is printed. This incrementing and printing step is not protected with [synchronization](http://docs.oracle.com/javase/tutorial/essential/concurrency/sync.html). It is not an [atomic operation](https://en.wikipedia.org/wiki/Linearizability). This means, the results can potentially become inconsistent. At the same time, this [critical section](https://en.wikipedia.org/wiki/Critical_section) is extremely small and executes extremely fast. This means that the error is virtually impossible to reproduce and to find. If such a programming mistake is made, it might only be discovered in production and would be extremely hard to identify.
26
26
27
27
If your application is running in GlassFish, you can access this JSP as [http://localhost:8080/myJSPs/counterUnsynchronized.jsp](http://localhost:8080/myJSPs/counterUnsynchronized.jsp).
### 1.4. Count Web Page Visits (synchronized): `counterSynchronized.jsp`
32
32
33
33
This JSP counts the number of times it was visited, but avoids the synchronization problem from the previous example above. It again creates a `long` member variable named `numVisitors`. This counter is increased by the private `synchronized` method `long __inc()`. This fixes the previous error.
34
34
35
35
If your application is running in GlassFish, you can access this JSP as [http://localhost:8080/myJSPs/counterSynchronized.jsp](http://localhost:8080/myJSPs/counterSynchronized.jsp).
This JSP includes a small form which allows you to rate the distributed computing course. You can choose between six different ratings. Clicking the submit button will send your chosen rating back to the same page. The internal counters will be updated in a synchronized fashion (see example 1.4 above). The response page of the rating contains a section displaying the ratings received so far. This example can therefore be used to get a rough impression on how the data from web forms is sent to a server and how the server can process it.
42
42
43
43
If your application is running in GlassFish, you can access this JSP as [http://localhost:8080/myJSPs/rating.jsp](http://localhost:8080/myJSPs/rating.jsp).
This JSP is an example for [session](https://en.wikipedia.org/wiki/Session_(computer_science)) data. A session is enriched with a [JavaBean](https://en.wikipedia.org/wiki/JavaBeans) named `cart` bound to class `shopping.Cart`. This bean basically holds a list of items in the user's shopping cart. The `shoppingCart.jsp` loads the bean, displays the contents of the shopping cart, and *includes* another JSP named `shoppingCartForm.jsp` which displays a form that allows us to add items to or remove items from the shopping cart. It therefore creates a form which, upon submission, sends it data back to the hosting JSP (`shoppingCart.jsp`). This data includes the parameter `submit`, which is either `add` or `remove` (or `null`, in which case nothing needs to be done) and the parameter `item`, representing the item to be added or removed. The `cart` bean therefore has read-only properties `add` and `remove` which receive the value of `item` and update the internal list, i.e., the content of the user's shopping cart. If we open this JSP from multiple different browsers, each will have an own, unique session and, hence, an own, unique instance of `shopping.Cart`.
50
50
51
51
If your application is running in GlassFish, you can access this JSP as [http://localhost:8080/myJSPs/shoppingCart.jsp](http://localhost:8080/myJSPs/shoppingCart.jsp).
### 1.7. Expression Language Examples: `expressionLanguageExamples.jsp`
@@ -60,24 +60,24 @@ This JSP includes a set of small examples for the expression language [EL](https
60
60
61
61
If your application is running in GlassFish, you can access this JSP as [http://localhost:8080/myJSPs/expressionLanguageExamples.jsp](http://localhost:8080/myJSPs/expressionLanguageExamples.jsp).
This JSP includes a set of small examples for the JavaServer Pages Standard Tag Library [JSTL](https://en.wikipedia.org/wiki/JavaServer_Pages_Standard_Tag_Library) which you can use since 2006.
68
68
69
69
If your application is running in GlassFish, you can access this JSP as [http://localhost:8080/myJSPs/jstlExamples.jsp](http://localhost:8080/myJSPs/jstlExamples.jsp).
### 1.9. Shopping Cart with JSTL and EL: `shoppingCartJSTLEL.jsp`
74
74
75
75
This is basically the same example as example 1.6, the session-based shopping cart. However, now we make use of both the JSTL and EL to simplify the example.
76
76
77
77
If your application is running in GlassFish, you can access this JSP as [http://localhost:8080/myJSPs/shoppingCartJSTLEL.jsp](http://localhost:8080/myJSPs/shoppingCartJSTLEL.jsp).
0 commit comments