首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

jsp动态换背景有关问题

2012-01-23 
jsp动态换背景问题有个index.html文件里面有4张图我想点一张图,test.jsp页面的背景就换一下我用Stringpre

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

热点排行