- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想删除 JTextPane 中的第一行并设置 setContentType("text/html");能够在 JTextPane 中使用 html 标签。
当我使用此代码时
setContentType("text/html");
try {
Element root = getDocument().getDefaultRootElement();
Element firstLine = root.getElement(0);
getDocument().remove(firstLine.getStartOffset(), firstLine.getEndOffset());
}
catch (Exception e) {e.toString();}
我遇到异常
javax.swing.text.BadLocationException: Invalid remove
如果我评论了 setContentType("text/html");我可以从 JTextPane 中删除第一行。
最佳答案
对于 HTMLEditorKit Element firstLine = root.getElement(0);
通常返回 <HEAD>
但你需要<BODY>
。遍历元素树,找到 BODY 并删除 BODY 的第一个子元素。
更新:该链接显示了一个可用于了解文档结构的工具。 http://java-sl.com/JEditorPaneStructureTool.html
您可以检查您拥有哪些元素,并确定应该删除哪个元素。
关于java - 如何删除 JTextPane 中的第一行并设置 setContentType ("text/html"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28695547/
我需要修改读取文本文件的代码,以动态方式读取文本或html文件。 现在代码仅使用 response.setContentType("text/plain"); 因为文件是以文本格式保存的。但我想保存为
response.setContentType(MIME)的作用是使客户端浏览器,区分不同种类的数据,并根据不同的MIME调用浏览器内不同的程序嵌入模块来处理相应的数据。 例如web浏览器就是通过M
我正在尝试在 spring-boot (1.2.2) 上返回一个图像 我应该如何设置内容类型? 以下都不适合我(意味着响应 header 根本不包含“内容类型” header ): @Requ
我正在尝试编写一个 Controller 来生成 CSV 电子表格以另存为文件。 我编写了以下操作和渲染方法 /** * Get the stats for the search. */ @Act
我有一个非常基本的问题: 我正在编写代码以使用 JSP 和 Servlet 下载 CSV 文件。我从互联网论坛上获得了代码并且工作正常,但我试图理解以下两行的重要性 response.setConte
我正在使用 Tomcat 6.0.20,HttpServlet 我的 servlet 代码如下:- response.setContentType("application/xml; charset=
只是想知道幕后是什么。实际上,我们似乎可以使用以下方式设置编码: response.setContentType("text/html; charset=UTF-8") response.setCha
本文整理了Java中org.apache.jackrabbit.webdav.WebdavResponse.setContentType()方法的一些代码示例,展示了WebdavResponse.se
本文整理了Java中org.openid4java.discovery.yadis.YadisResult.setContentType()方法的一些代码示例,展示了YadisResult.setCo
我想删除 JTextPane 中的第一行并设置 setContentType("text/html");能够在 JTextPane 中使用 html 标签。 当我使用此代码时 setContentTy
这个问题已经有答案了: Servlet filter wrapper - trouble changing content type (1 个回答) 已关闭 7 年前。 我试图在过滤器中将 gzip
当您 setContentType("text/html") 时,它仅适用于通过 JTextPane.setText() 设置的文本。通过样式放入 JTextPane 的所有其他文本对内容类型“免疫”
本文整理了Java中com.jetdrone.vertx.yoke.middleware.YokeResponse.setContentType()方法的一些代码示例,展示了YokeResponse.
我想下载服务器本身可用的文件 AppName\resources\attachemnts\file.extension(这可以是任何内容) 我从网上得到了代码,以下是相同的。 @RequestMapp
public class HelloWorld extends HttpServlet{ public void doGet(HttpServletRequest request,
我正在为 android 使用 spring。我想在我的 android 应用程序中创建注册表单。用户可能会用 utf-8 格式填写表格,但是当数据发送到服务器并存储在 MySQL 数据库中时,我发现
当我们在 java 中已经有 response.setContentType 时,我可以知道 response.addHeader 的使用吗...我找不到合适的解决方案。 这里上面的第二个语句足以
在我的 Controller 操作中,我尝试将响应的 contentType 设置为如下。 class MyController { def rss = { response.se
我是一名优秀的程序员,十分优秀!