首页 \ 问答 \ 图像没有在JSP中显示?(Image not showing in JSP?)

图像没有在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

enter image description here


原文: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.

相关问答

更多
  • 您不能在继承层次结构中“向后”投射。 你只能从电影到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 ...
  • 这是因为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 ...
  • 你可以做几件事: 拥有一个返回两种不同类型的函数是不理想的,因此您可以使用类方法处理转换。 如果print()函数也支持转换,这将有所帮助 考虑到这一点,我只是在类中移动了转换,并添加了一个str方法。 from fractions import gcd class Fraction: def __init__(self, numerator, denominator): self.numerator = numerator self.denominator = d ...
  • 查看System.Messaging.Message.Body属性,您可以看到它的Object类型。 这意味着MSMQ的消息传递框架负责为您进行序列化/反序列化。 文档声明通过Body属性传递的任何对象都必须是可序列化的: Body属性可以是任何可序列化的对象,例如文本字符串,结构对象,类实例或嵌入对象。 当你转换为你的对象类型时,肯定没有序列化。 Looking at the System.Messaging.Message.Body property you can see its of type Ob ...
  • 你为什么想这么做 ? 它完全没有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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)