【问题标题】:How to edit POST parameters in Firebug?如何在 Firebug 中编辑 POST 参数?
【发布时间】:2015-05-02 22:33:38
【问题描述】:

我在 Firefox for Mac 上使用 Firebug,以查看有关发送到服务器的请求数据的信息以及从服务器获取的响应。我的 Spring+Hibernate+JSF+MySQL 应用程序有问题;即我无法将新对象持久保存到数据库中。在 Eclipse 中,我有一个 XHTML 文件,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
    <h:head>
        <title>JSF Spring Hibernate Integration</title>
        <style type="text/css">
            .tg {
                border-collapse: separate;
                border-spacing: 0;
                border-color: #ccc;
            }

            .tg td {
                font-family: Arial, sans-serif;
                font-size: 14px;
                padding: 10px 5px;
                border-style: solid;
                border-width: 1px;
                overflow: hidden;
                word-break: normal;
                border-color: #ccc;
                color: #333;
                background-color: #fff;
            }

            .tg th {
                font-family: Arial, sans-serif;
                font-size: 14px;
                font-weight: normal;
                padding: 10px 5px;
                border-style: solid;
                border-width: 1px;
                overflow: hidden;
                word-break: normal;
                border-color: #ccc;
                color: #333;
                background-color: #f0f0f0;
            }

            .tg .tg-4eph {
                background-color: #f9f9f9
            }
        </style>
    </h:head>

    <h:body>
        <h1>Add a Person</h1>
        <h:form>
            <table>
                <tr>
                    <td><label>Name</label></td>
                    <td><h:inputText id="Name" value="#{person.name}"></h:inputText>
                    </td>
                </tr>
                <tr>
                    <td><label>Country</label></td>
                    <td><h:inputText id="country" value="#{person.country}"></h:inputText>
                    </td>
                </tr>
                <tr>
                    <td colspan="2"><h:commandButton
                            action="#{personService.addPerson(person)}" value="Add Person"></h:commandButton>
                    </td>
                </tr>

            </table>
        </h:form>

        <br />
        <h3>Persons List</h3>

        <c:if test="${!empty personService.listPersons()}">
            <table class="tg">
                <tr>
                    <th width="80">Person ID</th>
                    <th width="120">Person Name</th>
                    <th width="120">Person Country</th>
                </tr>
                <ui:repeat value="${personService.listPersons()}" var="person">
                    <tr>
                        <td>${person.id}</td>
                        <td>${person.name}</td>
                        <td>${person.country}</td>
                    </tr>
                </ui:repeat>
            </table>
        </c:if>
    </h:body>
</html>

我是 Firebug 的新手,对 Firebug 非常缺乏经验,但是在 Firebug 上检查 GET 和 POST 参数时,我发现了一些有趣的东西。单击 JSF 视图页面上的“添加人员”按钮后;用户输入“名称”和“国家/地区”字段的数据作为 POST 参数发送,名称为 j_idt6:Namej_idt6:country,而不仅仅是“名称”和“国家/地区”。此外,javax.faces.ViewState 对我来说似乎有点奇怪。这里是截图:

我不确定,但我想这可能会导致在我的数据库中持久保存新对象失败。这是我的问题:如何在 Firebug 上编辑这些参数?如何使它们正常工作?

【问题讨论】:

  • 你问错了问题是为了解决问题。

标签: jsf firebug


【解决方案1】:

Firebug 不允许您编辑请求参数,但如果您使用的是 Firefox,内置的开发工具允许这样做。

  1. 在 Windows/Linux 上按 Ctrl + Alt + QCmd + Alt kbd> + Q 在 Mac 上进入 Network 面板
  2. 重新加载页面
  3. 选择相关请求以打开侧面板
  4. Headers 侧面板中单击 Edit and Resend
  5. 编辑标题
  6. 点击发送

【讨论】:

  • 感谢您的回复。我已按照您的解释进行操作,但是当我在完成所有这些操作后重新加载页面时,我再次看到相同的 'j_idt6:Name' 和 'j_idt6:country' 内容:/
  • 我明白你现在在说什么了——抱歉,你不能永久更改浏览器中的代码——你需要去编辑器来做这件事。
  • 再次感谢。请问如何打开编辑器?
  • 我的意思是在你用来编写它的编辑器/IDE中打开你的代码
  • 抱歉,我有点困惑。我在 Eclipse 的 xhtml 文件中将名称框(或国家/地区框)定义为 &lt;td&gt;&lt;h:inputText id="Name" value="#{person.name}"&gt;&lt;/h:inputText&gt;。我应该在编辑器中修改这一行吗?
【解决方案2】:

只需右键单击文本框并选择检查元素。然后通过双击name 属性(或单击右键+编辑为HTML)重命名输入。并对第二个输入字段重复这些步骤。

或者您可以按照@Sam 所说的那样修改 POST 参数。

【讨论】:

  • 感谢回复。我已经按照您的解释编辑了这些输入名称。我编辑它们,单击“添加人员”按钮,再次看到相同的参数。我应该制作 ctrl+s 吗?
  • 你不需要保存任何东西,这是一个调试工具。您发送的 POST 请求包含修改后的名称。问题是,您在编辑这些输入后刚刚发送的请求是否向数据库添加了任何内容(我的意思是持续存在的问题)?如果不是,则问题与 JSF 生成的输入名称无关。
  • 好的,我明白了。请求没有再次将输入添加到 mysql。我不知道接下来要尝试什么..但非常感谢您的解释。
猜你喜欢
  • 2011-03-13
  • 2011-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-26
  • 1970-01-01
  • 2018-10-27
相关资源
最近更新 更多