我有一个JSP页面,其中有一个如下所示的超链接:
<p class='posDash1'>
<input type="hidden" name="export" value="export_csv">
<a href="/admin/" name ="export"><img class="csvFile" src="/images/excel_logo.gif"/> Export.csv</a>
</p>
Run Code Online (Sandbox Code Playgroud)
现在,如果我点击这个超链接,我需要在servlet中调用我的一个方法.所以在href中,我提供了我的servlet名称.一切都运行正常,这意味着每当我点击这个href时,我现在能够调用我的servlet我不知道如何在servlet中识别出这个调用是来自href链接点击.
所以我添加了一个输入隐藏值,我从中想到,我将能够识别出此调用来自href单击链接,但不知何故它不起作用:
public void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws Exception {
Response rr = null;
// but this always come as null
String export = req.getParameter(export);
if(export.equals("export_csv)) {
// do something here
}
// some code
}
Run Code Online (Sandbox Code Playgroud)
并且每次导出变量值都为null时,我无法识别此调用是否来自href链接点击.有没有办法克服这个问题?
<input>元素仅在使用时被序列化并发送<form>.您可以改为向您的href值添加查询字符串.
<a href="/admin?export=export_csv" name ="export">
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2344 次 |
| 最近记录: |