Jsp 提交dijit编辑器内容

Jsp 提交dijit编辑器内容,jsp,form-submit,dojo,rich-text-editor,Jsp,Form Submit,Dojo,Rich Text Editor,我正在努力学习dijit编辑器。我想用dijit编辑器小部件替换现有的文本区域,所以我编写了两个jsp——一个使用dijit.editor,它将编辑器内容提供给另一个jsp。 当我单击“提交”时,第二个jsp“结果”为编辑器显示空内容,无论在文本区域编辑器中键入什么内容 <script type="text/javascript"> dojo.require("dijit.Editor"); dojo.require("dijit._editor.plugins.

我正在努力学习dijit编辑器。我想用dijit编辑器小部件替换现有的文本区域,所以我编写了两个jsp——一个使用dijit.editor,它将编辑器内容提供给另一个jsp。 当我单击“提交”时,第二个jsp“结果”为编辑器显示空内容,无论在文本区域编辑器中键入什么内容

  <script type="text/javascript">
    dojo.require("dijit.Editor");
    dojo.require("dijit._editor.plugins.LinkDialog");
    dojo.require("dijit._editor.plugins.AlwaysShowToolbar");
  </script>
  <script type="text/javascript">
     dojo.addOnLoad(function(){
        alert("addOnLoad function");  
        dojo.connect(dojo.byId('form1'), 'onsubmit', function(){
            dojo.byId('editorContent').value= dijit.byId('content').getValue();
            alert("Hidden variable");
            alert(dojo.byId('editorContent').value);
            alert("Editor content");
            alert(dijit.byId('content').getValue());
         });
      });

</script>                   
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dijit/themes/claro/claro.css" />
</head>

  <body class=" claro ">
  <FORM id="form1" METHOD=POST ACTION="result.jsp">

  <table>
    <tr>
        <td>
        <input type="hidden" name="editorContent" />
            <div dojoType="dijit.Editor" id="content" onChange="console.log('editor1 onChange handler: ' + arguments[0])"
                plugins="['foreColor','|','bold','italic','underline','|','createLink', 'unlink']"
                extraPlugins="['dijit._editor.plugins.AlwaysShowToolbar']">
                    <p>
                        <b>This instance is created with a subset of functions enabled in the order
                        we want. </b>
                    </p>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                  <input type="submit" value="Submit" name="action"/>
             </td>  
        </tr>
    </table>        
   </form>    
  </body>
</html>
dijitEditor.jsp

  <script type="text/javascript">
    dojo.require("dijit.Editor");
    dojo.require("dijit._editor.plugins.LinkDialog");
    dojo.require("dijit._editor.plugins.AlwaysShowToolbar");
  </script>
  <script type="text/javascript">
     dojo.addOnLoad(function(){
        alert("addOnLoad function");  
        dojo.connect(dojo.byId('form1'), 'onsubmit', function(){
            dojo.byId('editorContent').value= dijit.byId('content').getValue();
            alert("Hidden variable");
            alert(dojo.byId('editorContent').value);
            alert("Editor content");
            alert(dijit.byId('content').getValue());
         });
      });

</script>                   
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dijit/themes/claro/claro.css" />
</head>

  <body class=" claro ">
  <FORM id="form1" METHOD=POST ACTION="result.jsp">

  <table>
    <tr>
        <td>
        <input type="hidden" name="editorContent" />
            <div dojoType="dijit.Editor" id="content" onChange="console.log('editor1 onChange handler: ' + arguments[0])"
                plugins="['foreColor','|','bold','italic','underline','|','createLink', 'unlink']"
                extraPlugins="['dijit._editor.plugins.AlwaysShowToolbar']">
                    <p>
                        <b>This instance is created with a subset of functions enabled in the order
                        we want. </b>
                    </p>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                  <input type="submit" value="Submit" name="action"/>
             </td>  
        </tr>
    </table>        
   </form>    
  </body>
</html>

require(“dijit.Editor”);
require(“dijit._editor.plugins.LinkDialog”);
require(“dijit._editor.plugins.AlwaysShowToolbar”);
dojo.addOnLoad(函数(){
警报(“添加加载功能”);
connect(dojo.byId('form1'),'onsubmit',function(){
dojo.byId('editorContent').value=dijit.byId('content').getValue();
警报(“隐藏变量”);
警报(dojo.byId('editorContent').value);
警告(“编辑内容”);
警报(dijit.byId('content').getValue());
});
});

创建此实例时,会按顺序启用函数子集
我们想要。

  <script type="text/javascript">
    dojo.require("dijit.Editor");
    dojo.require("dijit._editor.plugins.LinkDialog");
    dojo.require("dijit._editor.plugins.AlwaysShowToolbar");
  </script>
  <script type="text/javascript">
     dojo.addOnLoad(function(){
        alert("addOnLoad function");  
        dojo.connect(dojo.byId('form1'), 'onsubmit', function(){
            dojo.byId('editorContent').value= dijit.byId('content').getValue();
            alert("Hidden variable");
            alert(dojo.byId('editorContent').value);
            alert("Editor content");
            alert(dijit.byId('content').getValue());
         });
      });

</script>                   
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dijit/themes/claro/claro.css" />
</head>

  <body class=" claro ">
  <FORM id="form1" METHOD=POST ACTION="result.jsp">

  <table>
    <tr>
        <td>
        <input type="hidden" name="editorContent" />
            <div dojoType="dijit.Editor" id="content" onChange="console.log('editor1 onChange handler: ' + arguments[0])"
                plugins="['foreColor','|','bold','italic','underline','|','createLink', 'unlink']"
                extraPlugins="['dijit._editor.plugins.AlwaysShowToolbar']">
                    <p>
                        <b>This instance is created with a subset of functions enabled in the order
                        we want. </b>
                    </p>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                  <input type="submit" value="Submit" name="action"/>
             </td>  
        </tr>
    </table>        
   </form>    
  </body>
</html>
result.jsp

  <script type="text/javascript">
    dojo.require("dijit.Editor");
    dojo.require("dijit._editor.plugins.LinkDialog");
    dojo.require("dijit._editor.plugins.AlwaysShowToolbar");
  </script>
  <script type="text/javascript">
     dojo.addOnLoad(function(){
        alert("addOnLoad function");  
        dojo.connect(dojo.byId('form1'), 'onsubmit', function(){
            dojo.byId('editorContent').value= dijit.byId('content').getValue();
            alert("Hidden variable");
            alert(dojo.byId('editorContent').value);
            alert("Editor content");
            alert(dijit.byId('content').getValue());
         });
      });

</script>                   
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dijit/themes/claro/claro.css" />
</head>

  <body class=" claro ">
  <FORM id="form1" METHOD=POST ACTION="result.jsp">

  <table>
    <tr>
        <td>
        <input type="hidden" name="editorContent" />
            <div dojoType="dijit.Editor" id="content" onChange="console.log('editor1 onChange handler: ' + arguments[0])"
                plugins="['foreColor','|','bold','italic','underline','|','createLink', 'unlink']"
                extraPlugins="['dijit._editor.plugins.AlwaysShowToolbar']">
                    <p>
                        <b>This instance is created with a subset of functions enabled in the order
                        we want. </b>
                    </p>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                  <input type="submit" value="Submit" name="action"/>
             </td>  
        </tr>
    </table>        
   </form>    
  </body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html >
    <head>
        <title>Editor contents </title> 
    </head>
    <body>
        <%
            String val = request.getParameter("editorContent");    
            out.println("Dijit editor contents ="+val);  
         %>     
    </body>
</html>

编辑目录

不要将其绑定到表单的
onsubmit
,而是尝试通过小部件的
onChange进行绑定

  <script type="text/javascript">
    dojo.require("dijit.Editor");
    dojo.require("dijit._editor.plugins.LinkDialog");
    dojo.require("dijit._editor.plugins.AlwaysShowToolbar");
  </script>
  <script type="text/javascript">
     dojo.addOnLoad(function(){
        alert("addOnLoad function");  
        dojo.connect(dojo.byId('form1'), 'onsubmit', function(){
            dojo.byId('editorContent').value= dijit.byId('content').getValue();
            alert("Hidden variable");
            alert(dojo.byId('editorContent').value);
            alert("Editor content");
            alert(dijit.byId('content').getValue());
         });
      });

</script>                   
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dijit/themes/claro/claro.css" />
</head>

  <body class=" claro ">
  <FORM id="form1" METHOD=POST ACTION="result.jsp">

  <table>
    <tr>
        <td>
        <input type="hidden" name="editorContent" />
            <div dojoType="dijit.Editor" id="content" onChange="console.log('editor1 onChange handler: ' + arguments[0])"
                plugins="['foreColor','|','bold','italic','underline','|','createLink', 'unlink']"
                extraPlugins="['dijit._editor.plugins.AlwaysShowToolbar']">
                    <p>
                        <b>This instance is created with a subset of functions enabled in the order
                        we want. </b>
                    </p>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                  <input type="submit" value="Submit" name="action"/>
             </td>  
        </tr>
    </table>        
   </form>    
  </body>
</html>
为隐藏字段指定一个id:

  <script type="text/javascript">
    dojo.require("dijit.Editor");
    dojo.require("dijit._editor.plugins.LinkDialog");
    dojo.require("dijit._editor.plugins.AlwaysShowToolbar");
  </script>
  <script type="text/javascript">
     dojo.addOnLoad(function(){
        alert("addOnLoad function");  
        dojo.connect(dojo.byId('form1'), 'onsubmit', function(){
            dojo.byId('editorContent').value= dijit.byId('content').getValue();
            alert("Hidden variable");
            alert(dojo.byId('editorContent').value);
            alert("Editor content");
            alert(dijit.byId('content').getValue());
         });
      });

</script>                   
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dijit/themes/claro/claro.css" />
</head>

  <body class=" claro ">
  <FORM id="form1" METHOD=POST ACTION="result.jsp">

  <table>
    <tr>
        <td>
        <input type="hidden" name="editorContent" />
            <div dojoType="dijit.Editor" id="content" onChange="console.log('editor1 onChange handler: ' + arguments[0])"
                plugins="['foreColor','|','bold','italic','underline','|','createLink', 'unlink']"
                extraPlugins="['dijit._editor.plugins.AlwaysShowToolbar']">
                    <p>
                        <b>This instance is created with a subset of functions enabled in the order
                        we want. </b>
                    </p>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                  <input type="submit" value="Submit" name="action"/>
             </td>  
        </tr>
    </table>        
   </form>    
  </body>
</html>
<input type="hidden" name="editorContent" id='editorContent' />

等等当我键入此内容时,我意识到您正在
onsubmit
中调用
dojo.byId('editorContent')
,但您尚未将
id
属性分配给该表单字段。这可能是您的问题,您不必尝试我的
onChange
方法

  <script type="text/javascript">
    dojo.require("dijit.Editor");
    dojo.require("dijit._editor.plugins.LinkDialog");
    dojo.require("dijit._editor.plugins.AlwaysShowToolbar");
  </script>
  <script type="text/javascript">
     dojo.addOnLoad(function(){
        alert("addOnLoad function");  
        dojo.connect(dojo.byId('form1'), 'onsubmit', function(){
            dojo.byId('editorContent').value= dijit.byId('content').getValue();
            alert("Hidden variable");
            alert(dojo.byId('editorContent').value);
            alert("Editor content");
            alert(dijit.byId('content').getValue());
         });
      });

</script>                   
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dijit/themes/claro/claro.css" />
</head>

  <body class=" claro ">
  <FORM id="form1" METHOD=POST ACTION="result.jsp">

  <table>
    <tr>
        <td>
        <input type="hidden" name="editorContent" />
            <div dojoType="dijit.Editor" id="content" onChange="console.log('editor1 onChange handler: ' + arguments[0])"
                plugins="['foreColor','|','bold','italic','underline','|','createLink', 'unlink']"
                extraPlugins="['dijit._editor.plugins.AlwaysShowToolbar']">
                    <p>
                        <b>This instance is created with a subset of functions enabled in the order
                        we want. </b>
                    </p>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                  <input type="submit" value="Submit" name="action"/>
             </td>  
        </tr>
    </table>        
   </form>    
  </body>
</html>