Skip to content
Browse files

V0.3

  • Loading branch information...
1 parent d88a1a2 commit b31604bb7de35e5916118cfbf03c875ee6f10ce0 @mrohad committed
Showing with 64 additions and 20 deletions.
  1. +47 −12 README.markdown
  2. +2 −1 WWW/counter/sessionLogic.js
  3. +1 −0 WWW/counter/view.js
  4. +1 −0 WWW/counter/view.jssp
  5. +1 −1 knowBugs.txt
  6. +12 −6 lib/jssp.js
View
59 README.markdown
@@ -54,18 +54,19 @@ Explanation of properties:
- `server_script.begin` - the beginning tag for server-side scripting (default = <?)
- `server_script.end` - the end tag for server-side scripting (default = ?>)
- `server_script.session_minutes` - session timeout after X minutes (default = 30)
-- `server_script.memcached` - integration with memcached (Under construction)
+- `server_script.memcached` - integration with memcached
- `debug_mode` - 1 for debug mode, 0 for non-debug mode, on debug mode we add the exception to the response + the log level = debug
-- `nodes` - number of process running this application server( currently we don't support shared memory - under construction)
+- `nodes` - number of process running this application server ** currently we support shared memory using memcached! we recommand to set the number of nodes as the number of cores
# Features
- Handling request parameters easily (for GET and POST)
-- Session management, including timeout
-- Application scope management
+- Distributed session management, including timeout
+- Distributed application scope management
- Dynamic js loader (the lib folder)
- User can set the server-side script begin and end tags
+- Utilizing all the cores per cpu (the `nodes` settings parameter)
When one is writing a script nested to the <? some;JavaScript;Code;In Here;?> tags
@@ -75,13 +76,14 @@ He/She can use the following implicit functions/variables:
- `request.parameters` to read and write request post/get parameters
- `responseHead.header` to add headers of the response (e.g. responseHead.header["set-cookie"] = "..";)
- `responseHead.status` to change the HTTP response status
-- `write(str)` to add string to the response body (or instead one can use the <?=str?> tag)
-- `forward(other.jssp)` to forward the request and response to another server-side resource
-- `sendRedirect(url)` to send HTTP redirect response back to the client
+- `commands.write(str)` to add string to the response body (or instead one can use the <?=str?> tag)
+- `commands.forward(other.jssp)` to forward the request and response to another server-side resource
+- `commands.sendRedirect(url)` to send HTTP redirect response back to the client
- `lib.filename.member` to access whatever lib one has loaded
-- `session.put(key,value)` to put anything on the HttpSession
-- `session.get(key)` to get anything from the HttpSession
-- `application.someparam` to get someParam from the application scope
+- `session.set(key,value,callbackFunc)` to put anything on the HttpSession
+- `session.get(key,callbackFunc)` to get anything from the HttpSession
+- `application.set(key,value,callbackFunc)` to put anything on the application context
+- `application.get(key,callbackFunc)` to get anything from the application context
@@ -95,7 +97,7 @@ Once can achieve the same thing using Ex2.jssp
<? var a = 1+1;?><br/>
<?=a?>
-Once can forward from one jssp to another:
+One can forward from one jssp to another:
Exf1.jssp:
<? var dbInfo= gettingInfoFromDatabase();
request.parameters.db = dbInfo;
@@ -110,8 +112,41 @@ One can easily redirect:
<H1> Welcome...</H1>
<?}?>
+How to use the session scope, the counter Example: (separation of logic and view)
+logic.jssp:
+<?
+ var counter = 1;
+ session.get("counter",function(value){
+ log.debug("SESSIONLOGIC.JSSP, value - " +value);
+ if(value == undefined){
+ session.set("counter",1);
+ }else{
+ counter = value+1;
+ session.set("counter",counter);
+ }
+ request.parameters.counter = counter;
+ commands.forward("counter/view.jssp");
+ });
+?>
+view.jssp:
+ <HTML>
+ <HEAD><TITLE>Application Scope Counter Tester</TITLE></HEAD>
+ <BODY>
+ <?
+ var counter = request.parameters.counter;
+ if(counter==1)
+ commands.write("First Time");
+ else
+ commands.write("Number of hits by you:" + counter);
+
+ ?>
+ </BODY>
+ </HTML>
+
+In case Memcached is enabled, the application and session contexts are being saved there.
+
# Bugs and Contribution
-Please let me know if you find any bug or if you would like to contribute code: mrohad.jsf at gmail
+Please let us know if you find any bug or if you would like to contribute code: mrohad.jsf at gmail
Known Bugs - http://github.com/mrohad/Alligator/blob/master/knowBugs.txt
View
3 WWW/counter/sessionLogic.js
@@ -9,7 +9,8 @@
session.set("counter",counter);
}
request.parameters.counter = counter;
- commands.forward("counter/view.jssp");
+ commands.forward("counter/view.jssp");
+ d
});
})
View
1 WWW/counter/view.js
@@ -7,6 +7,7 @@ commands.writeEscapedText("%09");
commands.write("First Time");
else
commands.write("Number of users:" + counter);
+
commands.writeEscapedText("%09%3C/BODY%3E%0A");
commands.writeEscapedText("%3C/HTML%3E%0A");
View
1 WWW/counter/view.jssp
@@ -7,6 +7,7 @@
commands.write("First Time");
else
commands.write("Number of users:" + counter);
+
?>
</BODY>
</HTML>
View
2 knowBugs.txt
@@ -1,4 +1,4 @@
1) Currently using eval instead of require (http://groups.google.com/group/nodejs/browse_thread/thread/7a2e409ec970198e)
2) Crash when memcached crash
-
+3) fix examples on source
View
18 lib/jssp.js
@@ -169,16 +169,21 @@ function serverSideRunning(newfileName,request,response,file,lastMod,sessionId){
var responseHead= new Object();
var result = new Object();
result.html = "";
- var allGood = true;
+ var flushResponse = true;
+ var flushFunction = undefined;
+ var error = false;
responseHead.status = 200;
responseHead.headers = {};
var afterEval = [];
var currentAsemaphore = asemaphore.ctor(1,function(){
- result.html = afterEval.join("");
- if(allGood){//otherwise, forwarding...
+ if(!error)
+ result.html = afterEval.join("");
+ if(flushResponse){//otherwise, forwarding...
sendHeaders(request,response,responseHead,result.html.length,mime.mimeType(file,"text/html"),lastMod,result.sessionId);
response.end(result.html);
}
+ else if(flushFunction)
+ flashFunction();
});
var commands = {
write : function(text){
@@ -189,8 +194,8 @@ function serverSideRunning(newfileName,request,response,file,lastMod,sessionId){
afterEval.push(unescape(text));
},
forward :function(resource){
- handleRequest(request,response,resource,result.sessionId);
- allGood = false;
+ flushFunction = handleRequest(request,response,resource,result.sessionId);
+ flushResponse = false;
},
sendRedirect:function(url){
responseHead.status = 301;
@@ -237,7 +242,8 @@ function serverSideRunning(newfileName,request,response,file,lastMod,sessionId){
//log.debug("sessionId - "+result.sessionId);
}catch(err){
log.warn("parse problem:"+err);
- allGood = true;//yes all is good!!! :(
+ flushResponse = true;
+ error = true;
responseHead.status = 500;
result.html = ["<h1>",globalSettings.web_app_name," - SERVER ERROR</h1>."].join("");
if(globalSettings.debug_mode){

0 comments on commit b31604b

Please sign in to comment.
Something went wrong with that request. Please try again.