2015-05-02 27 views
1

我在Firefox的Mac上使用Firebug以查看有关发送到服务器的请求数据的信息以及从服务器获取的响应。我的Spring + Hibernate + JSF + MySQL应用程序出现问题;即我不能坚持新的对象到数据库。在Eclipse中,我有一个XHTML文件,如下所示:如何在Firebug中编辑POST参数?

<?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的检查GET和POST参数,我看到了一些有趣的事情对我来说。在JSF视图页面上单击“添加人员”按钮后,用户输入名称和国家/地区字段的数据将作为POST参数发送,名称为j_idt6:Namej_idt6:country,而不仅仅是“名称”和“国家”。此外,javax.faces.ViewState对我来说似乎有点奇怪。下面是它的屏幕截图:

enter image description here

enter image description here

我不是绝对肯定的,但我想,这可能在坚持我的database.Here一个新的对象导致失败是我的问题:我如何才能在编辑这些参数Firebug?如何使它们正常工作?

+1

你问的问题是错误的,以解决问题。 – BalusC

回答

6

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

  1. 命中按Ctrl + Alt键 + Q在Windows/Linux或Cmd的 + Alt键 + Q在Mac上才能到网络面板
  2. 重新加载页面
  3. 选择相关请求打开侧面板
  4. 在上编辑侧板点击重新发送
  5. 编辑页眉
  6. 点击发送
+0

谢谢reply.i已经跟着你的解释,但当我重新加载页面后,我看到相同的'j_idt6:名称'和'j_idt6:国家'的事情:/ – bsel

+0

我明白你现在说什么 - 对不起,您无法永久更改浏览器中的代码 - 您需要前往编辑器来执行此操作。 – saml

+0

再次感谢您可以告诉我如何打开编辑器? – bsel

0

只是在文本框中单击鼠标右键并选择检查元素。然后双击name属性(或点击右键+ 编辑为HTML),随意重命名输入。为第二个输入字段重复这些步骤。

Inline-editing the <code>name</code> attribute of an input

或者作为@Sam说,你可以修改POST参数。

+0

感谢您的reply.i已经编辑这些输入名称,正如你解释过的。我编辑它们,点击'添加人员'按钮,同样的参数再次被看到。我应该使ctrl + s或什么? – bsel

+0

你不需要保存任何东西,这是一个调试工具。您发送的POST请求包含修改后的名称。问题是,在编辑这些输入之后刚刚发送的请求是否向数据库添加了任何内容(我的意思是持续存在的问题)?如果不是,那么问题与JSF生成的输入名称无关。 – Abdullah

+0

好吧,我明白了你的意思。请求没有再添加到mysql的输入。我不知道下一步该怎么做..但是非常感谢你的解释。 – bsel