tms web core 通过URL 传递参数

时间:2023-03-09 06:46:01
tms web core 通过URL 传递参数

一般我们都会通过URL 给服务器传递很多参数,通过参数来决定对应的处理,今天就大概讲一下

如果通过URL 参数实现一些功能。

1、通过参数跳入不同的界面

首先我们先建立一个tms web core 工程文件。

除了主页面,我们再建两个页面,分别叫做第一个页面和第二个页面

tms web core 通过URL 传递参数

tms web core 通过URL 传递参数

tms web core 通过URL 传递参数

我们可以通过不同URL 参数直接进入不同的页面。

在工程文件里面做一下处理

var
s:string; begin
Application.Initialize; Application.AutoFormRoute := true;
Application.MainFormOnTaskbar := True; if HasQueryParam('page',s) then
begin
if s='one' then
Application.CreateForm(Tonepagef, onepagef);
if s='two' then
Application.CreateForm(TtwopageF, twopageF); end
else
Application.CreateForm(Tmainf, mainf); Application.Run;
end.

注意,要在uses 部分加上单元 WEBLib.WebTools。

我们现在运行这个例子

tms web core 通过URL 传递参数

不加参数,直接显示主页面

我们加上参数试一下

tms web core 通过URL 传递参数

tms web core 通过URL 传递参数

可以看见通过URL参数直接跳到我们需要的页面。

2、通过URL  参数给当前页面传递参数

在主页面放上对应的控件

tms web core 通过URL 传递参数

在formshow 事件里面加上对应的代码

procedure Tmainf.WebFormShow(Sender: TObject);
var
s:string;
begin
if HasQueryParam('arg1',s) then
WebLabel2.Caption:=s
else
WebLabel2.Caption:=''; if HasQueryParam('arg2',s) then
WebLabel5.Caption:=s
else
WebLabel5.Caption:=''; end;

运行这个程序

tms web core 通过URL 传递参数

正常显示传进来的参数

tms web core 通过URL 传递参数

汉字也可以正常处理。

题外话,由于URL 参数时SQL 注入的一个非常方便的一个途径,因此在实际程序处理过程中

使用URL 拼SQL 时,一定要注意,首先对输入的参数进行合法性验证,不可直接使用输入参数拼SQL。

另外,尽可能使用SQL参数方式处理输入值。