日期:2014-05-18  浏览次数:20786 次

jsp动态换背景问题
有个index.html文件里面有4张图我想点一张图,test.jsp页面的背景就换一下
我用
String   p=request.getParameter( "user ");
String   s=user.substring(25);
获得了图片的相对路径

但是怎么用这个变量s换背景呢?我的jsp刚刚学,所以我用的是js的
document.body.background方法,但是发现document.body.background=s根本不行

好像是jsp根js变量不能混用

代码:
==============================================
test.jsp


<%!   String   s;%>
<%
String   p=request.getParameter( "user ");
s=user.substring(25);
%>


<script   language= "javascript ">
document.body.background=s;
</script>
=========================================================

index.html

<script   language= "javascript ">
function   test(obj){
form1.user.value=obj.src;


form1.submit();

}
</script>
</head>
<body>
<form   id= "form1 "   name= "form1 "   method= "post "   action= "Test.jsp ">
<input   name= "user "   type= "text ";   onclick= "alert( "aaa ") "   />

</form>
<a   href=#;> <img   src= "image/banner.jpg "   alt= " "   width= "232 "   height= "166 "   border= "0 ";id= "img1 ";   onclick= "test(this) "/> </a>
<a   href=#;> <img   src= "image/login.gif "   alt= " "   width= "232 "   height= "166 "   border= "0 ";id= "img1 ";   onclick= "test(this) "/> </a>
<a   href=#;> <img   src= "image/rem.gif "   alt= " "   width= "232 "   height= "166 "   border= "0 ";id= "img1 ";   onclick= "test(this) "/> </a>
<a   href=#;> <img   src= "image/pic_foot.gif "   alt= " "   width= "232 "   height= "166 "   border= "0 ";id= "img1 ";   onclick= "test(this) "/> </a>
=====================================================================


------解决方案--------------------
<script language= "javascript ">
document.body.background=s;
</script>

改为
<script language= "javascript ">
document.body.background= ' <%=s%> ';
</script>
------解决方案--------------------
ding