我正在尝试创建用户注册表单并在注册时创建集合。我尝试了以下代码,但是当我尝试执行时出现此错误: HTTP 400 Bad Request and page cannot be displayed。这是代码:
xquery version "1.0";
declare namespace request="http://exist-db.org/xquery/request";
declare namespace response="http://exist-db.org/xquery/response";
declare namespace xdb="http://exist-db.org/xquery/xmldb";
declare option exist:serialize "method=xhtml media-type=text/html indent=yes";
declare variable $database-uri as xs:string { "xmldb:exist:///db" };
declare variable $redirect-uri as xs:anyURI { xs:anyURI("login.xql") };
declare function local:header() as node(){
<div style="background-color:#b0c4de; padding: 20px; border: 1px solid black;">
<h1>test</h1>
</div>
};
declare function local:footer() as node(){
<div style="background color:#eee; height: 1%; padding:20px; border: 1px solid black;">
<p>PROJECT</p>
</div>
};
declare function local:reg($user as xs: string) as element()?
{
let $password := request:get-parameter("password", "")
let $password2 := request:get-parameter("password2", "")
return
if (not(xdb:exists-user($user))) then (
xdb:create-collection($database-uri, $user),
xdb:create-user($user, $password, "guest", ()),
response:redirect-to($redirect-uri)
) else
<p>User already exists!</p>
};
declare function local:do-reg() as element()?
{
let $user := request:get-parameter("user", ())
return
<p>{$user}</p>
if($user) then
local:reg($user)
else ()
};
<html>
<head><title>Registration</title>
</head>
<body>
{local:header()}
<h1>Forma for reg</h1>
<form action="{request:get-uri()}">
User Name: <br />
<input type="text" name="user" size="20" />
<br />
Password: <br />
<input type="password" name="password" size="20" />
<br />
Confirm: <br />
<input type="password" name="password2" size="20" />
<br />
<input type="submit" />
<input type="reset" name="reset" value="Clear" />
</form>
{local:do-reg()}
{local:footer()}
</body>
</html>
请帮忙,我是 xquery 的初学者并且存在数据库。提前致谢!