php转jsp

ttuurr 2008-09-04 07:22:47
《Bulletproof Ajax中文版》第5章 有个formlogic.php,但是我没学过php,有谁能把它转成jsp文件吗?谢谢了!

formlogic.php如下:

<?

$output = '';

$required = array('email','name','message');

$errors = array();

if (isset($_REQUEST['submit'])) {

foreach ($required as $field) {

if (empty($_REQUEST[$field])) {

$errors[$field] = 'this is required';

}
}

if (count($errors) <1) {

// Send an email

$output.= ' <p class="feedback">';
$output.= 'Thank you for getting in touch';
$output.= ' </p>';

echo $output;
return;

}
}

$output.= '
<form method="post" id="contactform" action="'.$_SERVER['PHP_SELF'].'">';

$fields = array(
'name' => 'text',
'email' => 'text',
'message' => 'textarea'
);

foreach ($fields as $field => $type) {

$output.= '
<p>';
$output.= '
<label for="'.$field.'">';
$output.= ucwords($field);
if (isset($errors[$field])) {
$output.= ' <strong class="error">is required </strong>';
}
$output.= ' </label>';

switch ($type) {

case 'textarea':
$output.= '
<textarea name="'.$field.'" id="'.$field.'" cols="30" rows="10">';
if (isset($_REQUEST[$field])) {
$output.= htmlspecialchars($_REQUEST[$field]);
}
$output.= '
</textarea>';
break;

default:
$output.= '
<input type="text" name="'.$field.'" id="'.$field.'"';
if (isset($_REQUEST[$field])) {
$output.= ' value="'.htmlspecialchars($_REQUEST[$field]).'"';
}
$output.= ' />';
break;

}

$output.= '
</p>';

}

$output.= '
<p>
<input type="submit" name="submit" value="Submit" />
</p>
</form>
';

echo $output;

?>
...全文
85 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
QQBOP 2008-09-04
  • 打赏
  • 举报
回复
程序员,还想没日没夜的干下去吗??最新项目:懂网络,零投入,不耽误正常工作,业余时间让你月赚2000!!!!!!

财富网址:www.dmdigo.cn
xiongbing529 2008-09-04
  • 打赏
  • 举报
回复
语言相通的把..呵呵
ten789 2008-09-04
  • 打赏
  • 举报
回复
帮你注释还差不多

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧