简体   繁体   English

当条件为真时,我正在尝试显示图像。但我遇到了错误<img>请帮助我

[英]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.

相关问题 尝试 setOnClickListener 时出现错误 - I am getting error when trying to setOnClickListener 我正在尝试在 Java 中呈现一个蓝色方块,但出现 IllegalStateException 错误。 有人能帮我吗? - I'm Trying To Render A Blue Square In Java But I Am Getting A IllegalStateException Error. Can Someone Help Me? 为什么在类型转换器的帮助下尝试在 Room 数据库中保存列表时出现错误? - Why am I getting an error when trying to save a list in Room database with the help of a type converter? 在 Java 中,为什么我在尝试显示 FileNotFoundException 时会收到 NullPointerException? - In Java, why am I getting a NullPointerException when trying to display a FileNotFoundException? 当我在eclipse上借助appium运行程序时,出现会话未创建错误 - When I am running program with the help of appium on eclipse i am getting session not created error 当我尝试在我的 maven 项目中使用 @ResController 时,它显示错误“RestController 无法解析为类型”。帮我解决这个问题 - When i am trying to use @ResController in my maven project it showing error “ RestController can not be resolved to a type”.Help me to resolve this 尝试使用ViewPager和GridView在android中创建图像库时出现错误 - I am getting error when trying to create an image gallery in android using ViewPager and GridView 为什么在尝试与我的服务器通信时出现此错误? - Why am i getting this error when trying to communicate with my server? 尝试使用 AWS CodeGuru 时出现此错误 - I am getting this error when trying to user AWS CodeGuru 我正在尝试启动 Mozilla,但仍然收到此错误 - I am trying to launch Mozilla but still I am getting this error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM