JSP基础语法含义:<%! %>,<% %>,<%= %>

文章详细阐述了JSP文件中如何定义全局变量和局部变量,以及_jspService方法内如何进行页面输出。全局变量在类jsp中声明,局部变量在jspService方法内定义,而页面输出是通过response.write()实现的。
在当前JSP.java文件中定义的全局变量
<%! 全局变量内容 %>

//在java源码中如下:
class jsp{
    String username;
}
在jsp.java文件中_jspService方法中定义的变量
<% 局部变量内容 %>

//编译java文件中局部变量意思
class jsp{
    void jspService(){
        String password="123456";
    }
}
在jsp文件中的_jspServicec方法中向页面输出的参数
<%= 输出内容 %>

//编译java文件中页面输出意思
class jsp{
    void jspService(){
        String word="123456";
        response.write().write(输出内容);//即<%= 输出内容 %>
    }
}
以原生php模板而不是html模板改写下文 <!DOCTYPE html> <html> <head> <title>调试信息</title> <style> .debug-section { margin: 20px 0; padding: 15px; border: 1px solid #ddd; border-radius: 5px; background-color: #f9f9f9; } .debug-section h2 { margin-top: 0; color: #333; border-bottom: 1px solid #eee; padding-bottom: 10px; } .debug-item { margin-bottom: 15px; padding: 10px; background-color: #fff; border: 1px solid #eee; border-radius: 3px; } .debug-item pre { background-color: #f5f5f5; padding: 10px; border-radius: 3px; overflow-x: auto; } .empty-message { color: #999; font-style: italic; } </style> </head> <body> <h1>系统调试信息</h1> <!-- Session 数据 --> <div class="debug-section"> <h2>Session 数据</h2> {if empty($sessionData)} <p class="empty-message">Session is empty</p> {else} {foreach $sessionData as $name => $value} <div class="debug-item"> <strong>Session Name:</strong> {$name|htmlspecialchars}<br> <strong>Value:</strong> <pre>{$value|print_r|htmlspecialchars}</pre> </div> {/foreach} {/if} </div> <!-- 普通 Cookie 数据 --> <div class="debug-section"> <h2>普通 Cookie 数据</h2> {if empty($cookieData)} <p class="empty-message">No cookies found</p> {else} {foreach $cookieData as $name => $value} {if $name != 'waxx' || !is_array($value)} <div class="debug-item"> <strong>Cookie Name:</strong> {$name|htmlspecialchars}<br> <strong>Value:</strong> <pre>{$value|print_r|htmlspecialchars}</pre> </div> {/if} {/foreach} {/if} </div> <!-- 原站点数组形式 Cookie --> <div class="debug-section"> <h2>原站点数组形式 Cookie (waxx)</h2> {if empty($waxxCookie)} <p class="empty-message">No waxx cookies found</p> {else} {foreach $waxxCookie as $key => $value} <div class="debug-item"> <strong>Cookie Name:</strong> waxx[{$key|htmlspecialchars}]<br> <strong>Value:</strong> <pre>{$value|print_r|htmlspecialchars}</pre> </div> {/foreach} {/if} </div> </body> </html>
最新发布
07-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值