[英]I am trying display image when condition is true.but i am getting error in <img> tage pls help me
<%
String optionselected =request.getParameter("digram");
out.print(optionselected);`
if(optionselected.equals("1"))
<img src="C:\Users\jitutjs\workspace\dispImpl\Traing.jpg"/>
else
if(optionselected.equals("2"))
<img src="C:\Users\jitutjs\workspace\dispImpl\WebContent\Circle.jpg"/>
else
out.print("no diagarm");
%>
<img src="..." />
is not related to java, it is a html
tag, all that is inside the scriplets is treated as java code. <img src="..." />
与 java 无关,它是一个html
标签,scriplets 中的所有内容都被视为 java 代码。 If you want to use scriplets, you must do it like this:如果你想使用scriplets,你必须这样做:
<%
String optionselected =request.getParameter("digram");
out.print(optionselected);`
if(optionselected.equals("1"))
%>
<img src="C:\Users\jitutjs\workspace\dispImpl\Traing.jpg"/>
<%
else
if(optionselected.equals("2"))
%>
<img src="C:\Users\jitutjs\workspace\dispImpl\WebContent\Circle.jpg"/>
<%
else
out.print("no diagarm");
%>
PS My advice is to not use scriplets, they are old and deprecated. PS 我的建议是不要使用 scriplets,它们已经过时且已弃用。 It is better to take a look at JSTL tag library.最好看看JSTL标记库。
img
tag should be out of scriplest. img
标签应该是最简单的。 Also, You have given the src value in wrong way, you can use absolute path of your web-app as <img src="/Circle.jpg"/>
as this may vary when application is deployed elsewhere.此外,您以错误的方式提供了 src 值,您可以使用 Web 应用程序的绝对路径作为<img src="/Circle.jpg"/>
因为当应用程序部署在其他地方时这可能会有所不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.