我对 ColdFusion 很陌生(昨天开始)。我正在尝试在中创建一个会话变量checklogin.cfm
,它等于从表单输入的用户名。所以我可以在结果页面上显示用户名。有可能这样做吗?或者有没有更好的方法来做到这一点?
应用程序.cfm
<cfset this.name = "Name of your application">
<cfset this.sessionManagement = true>
check_login.cfm
<!--- If username equals user1 and password equals password1, take user to home page. --->
<cfif form.userName eq "user1" AND form.password eq "password1">
<cfset session.userName = form.userName/>
<cflocation url="home.cfm" ADDTOKEN="Yes">
<!--- If username doesn't equal user1 and/or password doesn't
equal password1, take user back to login page. --->
<cfelse>
<cflocation url="login.cfm" ADDTOKEN="Yes">
</cfif>
主页.cfm
<cfoutput>
<br>
<b><font size="6">Enter the numbers you want to add:</font></b>
</cfoutput>
<!--- Add numbers form --->
<cfform action="result.cfm" method="post">
<!--- Get numbers from user --->
<p>
Enter first number:
<cfinput type="Text" name="number1" required="Yes" size="20"
maxlength="100" message="You must enter a number.">
<br>
Enter second number:
<cfinput type="Text" name="number2" required="Yes" size="20"
maxlength="100" message="You must enter a second number.">
<br>
</p>
<!--- submit button --->
<cfinput type="Submit" name="submitForm" value="Submit">
</cfform>
登录.cfm
<cfform action="check_login.cfm" method="post">
<!--- Get login info from user --->
<p>
UserName:
<cfinput type="Text" name="userName" required="Yes" size="20" maxlength="25"
message="Username is required and must be less than 25 characters.">
<br>
Password:
<cfinput type="password" name="password" required="Yes" size="20" maxlength="20"
message="Password is required and must be less than 20 characters.">
<br>
</p>
<!--- submit button --->
<cfinput type="Submit" name="submitForm" value="Submit">
</cfform>
结果.cfm
<cfset result = form.number1 + form.number2 >
<cfoutput>
<b><font size="6">Hi #session.userName#! </font></b><br>
<br>
<!-- Display result to user. -->
<font size="5">Your result is: #result#</font>
</cfoutput>
问题出在结果页面上,它说Element USERNAME is undefined in SESSION
指向行<b><font size="6">Hi #session.userName#! </font></b>