图像没有在JSP中显示?(Image not showing in JSP?)
我有简单的JSP网页,但它不显示图像
这是我的JSP页面,它将从Web内容下的图片文件夹中获取图像
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <img width = "80" src="${pageContext.request.contextPath}/pics/"> </body> </html>
但是页面看起来像这样
I do have simple JSP web page, but it's not displaying an image
This is my JSP page where it will fetch the image from pics folder under web content
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <img width = "80" src="${pageContext.request.contextPath}/pics/"> </body> </html>
But the page looks like this
原文:https://stackoverflow.com/questions/50770081
更新时间:2022-07-03 06:07
最满意答案
你可以做几件事:
- 拥有一个返回两种不同类型的函数是不理想的,因此您可以使用类方法处理转换。
- 如果print()函数也支持转换,这将有所帮助
考虑到这一点,我只是在类中移动了转换,并添加了一个str方法。
from fractions import gcd class Fraction: def __init__(self, numerator, denominator): self.numerator = numerator self.denominator = denominator self.simplify() def __str__(self): if self.denominator == 1: return str(self.numerator) return '{}/{}'.format(self.numerator,self.denominator) def simplify(self): div = gcd(self.numerator, self.denominator) self.numerator //= div self.denominator //= div def convert(fraction): if fraction.denominator == 1: return fraction.numerator # int return fraction # Fraction if __name__ == '__main__': f = Fraction(6, 2) c = Fraction.convert(f) print(f) print(c) f2 = Fraction(3, 4) print(f2)
看看它是否可以帮到你。
There are a couple of things you can do:
- It is not optimal to have a function which returns two different types, so you could handle the conversion with a class method.
- It would help if the conversion was supported in the print() func as well
With that in mind, I just moved convert inside the class, and added a str method as well.
from fractions import gcd class Fraction: def __init__(self, numerator, denominator): self.numerator = numerator self.denominator = denominator self.simplify() def __str__(self): if self.denominator == 1: return str(self.numerator) return '{}/{}'.format(self.numerator,self.denominator) def simplify(self): div = gcd(self.numerator, self.denominator) self.numerator //= div self.denominator //= div def convert(fraction): if fraction.denominator == 1: return fraction.numerator # int return fraction # Fraction if __name__ == '__main__': f = Fraction(6, 2) c = Fraction.convert(f) print(f) print(c) f2 = Fraction(3, 4) print(f2)
See if it can help you.
相关问答
更多-
将对象转换为继承的对象(Convert Object to Inherited Object)[2023-06-25]
您不能在继承层次结构中“向后”投射。 你只能从电影到MyMovie,而不是相反。 如果要向现有Movie对象添加额外的内容,请向MyMovie添加一个构造函数,该构造函数将Movie对象作为参数并手动复制成员变量。 You can't cast "backwards" in inheritance hierarchies. You can only go from Movie to MyMovie, not the other way around. If you want to add extra stu ... -
循环槽的属性与for .. in和任何属性不是一个对象替换一个。 喜欢这个: let x = { "Results": { "circle": 0.06879016757011414, "quad": { "exp": 0.8039023876190186, "actual": 0.19609761238098145 }, "square": 0.8266428709030151 } } for (key in x.Resu ...
-
将对象转换为C#类(Convert object to a C# class)[2024-04-01]
这是因为details是List,它与StoreToStoreRequestDetailsModel的单个实例StoreToStoreRequestDetailsModel 。 所以你应该这样做: List y = x.details; 如果要访问该列表中的特定项目,则应循环遍历它们并找到所需的项目。 或者使用索引或其他获取特定项的方法。 例如,您可以得到的第一项: StoreToStoreRequestDetailsModel f ... -
通过调用静态方法(如单例)来拉取对象是一种不好的做法(甚至是反模式)。 单例和静态类对于新手来说是自然的,因为它们的工作方式与我们在程序范例中学到的方式相同,但你应该避免使用它们(只有在没有状态时才使用静态类) 您应该完全将对象作为参数传递,以避免引入隐式依赖项,并执行良好的OOP。 阅读有关依赖注入的信息 。 如果对象创建变得复杂或烦人,您始终可以使用依赖注入容器 Pulling objects by calling static methods (like in singleton) is a bad ...
-
什么是System.out.println(pObject.getClass().getName()); 如果它的Customer类相同,则可以像这样投射对象 Customer cust = (Customer) pObject; Whats the output of System.out.println(pObject.getClass().getName()); If its the same Customer class, then you could cast the object like th ...
-
不,不同类别代表不同的类型,即使它们具有相同的内容。 您应该在顶部使用一个包含所有共享数据的AnimalDetails的类型层次结构。 您仍然可以从您的web服务返回专用类型,但共享代码来构建它们。 例如,考虑下面的类型定义: class AnimalDetails { public string Name { get; set; } public float Height { get; set; } public float Weight { get; se ...
-
将对象转换为另一个类(Convert object to another class)[2023-06-14]
你可以做几件事: 拥有一个返回两种不同类型的函数是不理想的,因此您可以使用类方法处理转换。 如果print()函数也支持转换,这将有所帮助 考虑到这一点,我只是在类中移动了转换,并添加了一个str方法。 from fractions import gcd class Fraction: def __init__(self, numerator, denominator): self.numerator = numerator self.denominator = d ... -
将对象转换为实际的类(casting object to the actual class)[2021-11-05]
查看System.Messaging.Message.Body属性,您可以看到它的Object类型。 这意味着MSMQ的消息传递框架负责为您进行序列化/反序列化。 文档声明通过Body属性传递的任何对象都必须是可序列化的: Body属性可以是任何可序列化的对象,例如文本字符串,结构对象,类实例或嵌入对象。 当你转换为你的对象类型时,肯定没有序列化。 Looking at the System.Messaging.Message.Body property you can see its of type Ob ... -
将对象数组转换为对象(Convert array of objects to object)[2023-07-14]
你为什么想这么做 ? 它完全没有JSON字符串化一个项目数组,你会得到一个像这样的结构 "[{},{},{},...]" 这可能是一个优势,因为你保证物品的顺序 。 Why would you want to do that ? Its totally fine to JSON stringify an Array of items, you'll get a structure like "[{},{},{},...]" that is probably even an advantage, beca ... -
我建议只使用Vector()类和布尔normalized实例属性。 此外,在normalize方法中,您使用的是x , y和z,但这些变量未定义,您甚至无法使用self读取它们。 我建议的代码: from math import sqrt class Vector(object): def __init__(self, x, y, z, normalized=False): self.v = [x, y, z] if normalized in [True ...