ASP中的嵌套字符串操作

时间:2014-05-20 20:20:07

标签: html asp.net tcl

我正在尝试在ASP中嵌套字符串操作,但我收到错误。我对此很陌生,所以我不确定自己哪里出错了。任何帮助都会很棒。这就是我所拥有的:

表单页面:

<form method="post" action="ping.asp">
Subnet: <input type="text" name="subnet" value="XXX.XXX.XXX"><br>
First IP: <input type="text" name="first_ip" value="XXX"><br>
Last IP: <input type="text" name="last_ip" value="YYY"><br>
<input type="radio" name="OS" value="CISCO" /> IOS 
<input type="radio" name="OS" value="CMD" /> Command Prompt <br>
<br>
<br>
<input type="submit" value="Submit">
</form>

ASP文件:

<%
strHeading = "<h1>IOS AND COMMAND PROMPT RANGE PING BUILDER" & "</h1>"

strOS = Request.Form ("OS")
if strOS ="CISCO" then
strWrite = "<br>tclsh<br>for {set n <%=request.querystring("first_ip")%>} {$n<=<%=request.querystring("last_ip")%>} {incr n} {<br>if { [regexp &#34;(!)&#34; [exec &#34;ping <%= Request.QueryString("subnet") %>.$n timeout 1 repeat 1&#34; ]] } {<br>puts &#34;<%=Request.QueryString("subnet")%>.$n&#34;<br>          } else { puts &#34;<%=Request.QueryString("subnet")%>.$n **** failed ***&#34; }<br>          }<br><br>"

elseif strOS ="CMD" then
strWrite = "<br>for /L %z in (< % Request.QueryString("first_ip")% >,1,< % Request.QueryString("last_ip")% >) do @ping < % Request.QueryString("subnet"% >.%z -w 10 -n 1 | find &#34;Reply&#34;<br>"

else
strWrite = "Please select either IOS or Command Prompt."
End if
%>

<html>
<head>
<title>Range Ping Creator</title>
</head>
<body align=center>

<% Response.Write strHeading %>
<br>
<br>
<br>
<% Response.Write strWrite %> 
<br>
<br>
<br>
</body>
</html>

应根据无线电选择输出以下内容。如果我用纯文本替换strWrite文本,而不是操作,它可以正常工作。任何提示?

正确输出:

for / L%z in(XXX,1,YYY)do @ping XXX.XXX.XXX。%z -w 10 -n 1 |找到&#34;回复&#34;

tclsh的
for {set n XXX} {$ n&lt; = YYY} {incr n} {
如果{[regexp&#34;(!)&#34; [exec&#34; ping XXX.XXX.XXX。$ n timeout 1 repeat 1&#34; ]]} {
puts&#34; XXX.XXX.XXX。$ n&#34;
          } else {puts&#34; XXX.XXX.XXX。$ n **失败* &#34; }
          }

1 个答案:

答案 0 :(得分:0)

经典ASP的工作方式字符串连接就像这样(它使用&符号连接):

strWrite = myOS & " some string here " & request.querystring("some_ip") & " and then more stuff."

当你在执行代码块时(&lt;%和%&gt;之间的东西,它是所有常规VBScript / ASP的东西,不再需要内联代码(使用&lt;%=和%&gt;)

<%
strWrite = myOS & " is an operating system using the IP: " & request.querystring("ip_address") & "!"

'do more stuff here

%>

<HTML>
<HEAD>
<TITLE><%=mystring_title_variable_here%></TITLE>
</HEAD>
<BODY>
Hey there, folks.  This is what I know:
<P><%=strWrite%></P>
</BODY>
</HTML>

给出了两种方式使用它们的例子。