私が作成している Web サイトでユーザーに Cookie を送信してから、Web ページを表示しようとしています。
だから私はhttp://alexmarandon.com/articles/mochiweb_tutorial/をクッキーの作り方に関する唯一の本当のチュートリアルとして見つけましたが、私にとってはエラーになるようです.
私のループは次のようになります (私の make_cookie、get_cookie_value、render_ok、および get_username は、'username' の代わりに 'mename' をキーとして使用することを除いて、彼と同じです):
loop(Req, DocRoot) ->
"/" ++ Path = Req:get(path),
try
case dispatch(Req, valid_urls:urls()) of
none ->
case filelib:is_file(filename:join([DocRoot, Path])) of
true ->
%% If there's a static file, serve it
Req:serve_file(Path, DocRoot);
false ->
%% Otherwise the page is not found
case Req:get(method) of
Method when Method =:= 'GET'; Method =:= 'HEAD' ->
case Path of
"response" ->
QueryStringData = Req:parse_qs(),
Username = get_username(Req, QueryStringData),
Cookie = make_cookie(Username),
FindCookie = get_cookie_value(Req,"mename","Not Found."),
% render_ok(Req, [Cookie], greeting_dtl, [{username, Username}]),
Req:respond({200, [{"Content-Type", "text/html"}],
"<html><p>Webpage</p></hmtl>"});
_ ->
Req:not_found()
end
end
end;
Response ->
Response
end
catch
Type:What ->
Report = ["web request failed",
{path, Path},
{type, Type}, {what, What},
{trace, erlang:get_stacktrace()}],
error_logger:error_report(Report),
%% NOTE: mustache templates need \ because they are not awesome.
Req:respond({500, [{"Content-Type", "text/plain"}],
"request failed, sorry\n"})
end.
私が得るエラーは次のとおりです。
[error] "web request failed", path: "response", type: error, what: undef, trace: [{greeting_dtl,render,[[{username,"GET"}]],[]}
エラーは render_ok から来ているようですが、Erlang-mochiweb を初めて使用するので、これを修正する方法がわかりません。