3
votes

I am doing program that use prolog to be integrated with HTML and currently stuck at understanding HTTPSESSION in prolog and want to create same function as the JSP below.

HTML input from user:

`<form action="page2.jsp" method="post">
    <label>Name:</label>
    <input type="text" name="patientname" placeholder="Name">
    <input type="submit" value="Next">
</form>`

JSP taking input from HTML:

`<%
String name = request.getParameter("patientname");
 session.setAttribute("patientname", name);
%>`

anyone can help? I already seen the http://www.swi-prolog.org/pldoc/man?section=httpsession but still cant understand how to implement the code in prolog.

I think basically you want to do something like http_session_asserta(patientname(Name)) to add that fact to the session. Later you'd obtain it with http_session_data(patientname(Name)) to unify Name with the current session's patient name. - Daniel Lyons
I believe you can obtain the form value with something like http_parameters(Request, _, [form_data(Values)]), member(patientname=PatientName, Values). - Daniel Lyons
what is difference between http_session_asserta() and http_session_assert(). Now I am having difficulities due to whenever I submit a new form the parameters I call and http_session_data() will replaced my old data .I dont want my I old data to be replaced. - beginner
It's the same as asserta/1 and assert/1. The former is standard, because you can assert multiple facts with the same arity into the database, the a suffix says "at the beginning of the database" (i.e. before the other facts you already have) versus z meaning "at the end" (i.e. after the others). I generally avoid assert/1 because it is non-standard and leaves the question open. If you don't want your old data replaced, check for it before asserting it. That's just programming. - Daniel Lyons
page_content(Request) --> { http_parameters(Request,[patient(Patient,[optional(true)])]), http_session_asserta(-Patient) }, Here I had insert first form value to the asserta/1 in next_page.pl and later I insert second form value to the asserta/1 in next_page2.pl page_content(Request) --> { http_parameters(Request,[age(Age,[optional(true)])]), http_session_asserta(-Age), http_session_data(Patient) },.When I had enter new value to asserta/1 the value will read the age value instead. Or is it another way I can use http_session_data() to get both value. - beginner