日期:2014-05-17  浏览次数:20601 次

在jsp中如何嵌入javascript?
整体结构是这样的:从index.jsp页面中上传一个文件,代码如下:
<%@ page contentType="text/html; charset=GBK" pageEncoding="GBK" %>
<%
String message=(String)request.getAttribute("result");
%>
<form action="upServlet" method="post" enctype="multipart/form-data">
<table align="center">
<tr>
<td colspan="2" align="center">
【应用commons-fileUpload限制上传文件类型】
</td>
</tr>
<tr>
<td>选择文件 </td>
<td><input type="file" name="file"/></td>
</tr>
<tr>
<td></td>
<td align="left">
<input type="submit" value="开始上传"/>
</td>
</tr>
</table>
</form>

其中result的值在upServlet中定义,用来记录文件上传成功或失败,我想在点击开始上传按钮后能弹出显示result值的对话框,就是javascript中alert那种形式的,可是定义的javascript怎么也显示不出来,求教各位高手!调试证明这个页面的message在每次上传一个文件是可以得到正确的值的,就是script代码不能执行,浏览器是IE9,浏览器设置没有错误。

------解决方案--------------------
<script>
alert('<%=message>')
</script>
------解决方案--------------------
探讨

引用:

<script>
alert('<%=message>')
</script>

那在form里面怎么调用啊?

------解决方案--------------------
<html>
<head>
<script language="javascript">

function check(){

。。。。。

document.getElementById("loginForm").submit();
}
</script>
</head>
  
<body>
<center>

<form action="<%=basePath%>***.action" method="post" id="loginForm">

<table >
  <tr>
<td><input type="button" value="按钮" onclick="check()"/></td>
</tr>

</table>
</form>
</center>
</body>
</html>