话说当遇到问题的时候,还真的应该仔细想想,把道理理清楚,那么问题自然就不攻自破了。
嗯嗯~~
环境:spring mvc 2.5、FCKeditor2.3
FCKeditor的配置不赘述,google之。。。
问题:在页面内嵌入如下代码,在页面和控制台都不报错,但是也不显示任何东西,空白一片。
<form action="shou.jsp" method="post" target="_blank">
<textarea id="f_content" name="f_content" cols="10" rows="11">input</textarea>
<script type="text/javascript">
var oFCKeditor = new FCKeditor('f_content','600px','300px','Basic','hello~~~') ;
oFCKeditor.BasePath = "FCKeditor/";//实际目录参考:和WEB-INF在同一层。注意前边不能有/,后边必须有/
//oFCKeditor.ToolbarSet = 'Default';
//oFCKeditor.Height = 500 ;
oFCKeditor.ReplaceTextarea(); //替换文本域
</script>
</form>
解决方法:
在web.xml里,spring mvc 的dispatcher servlet监听的url匹配范围缩小,逼开对所有html(如*.html)的请求处理。例如,配置为:
<servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping>
原因:
FCKeditor实际上是在页面里嵌入了一个html文件:"/FCKeditor/editor/fckeditor.html".
如果spring的servlet把FCKeditor的这个请求也截获了的话,那么就必然会到xxx-dispatcher.xml里去找匹配,然后就要进入到一个Controller里去处理,而FCKeditor的这个请求“/FCKeditor/editor/fckeditor.html“实际上是带了参数的,象:/FCKeditor/editor/fckeditor.html?id=xxxx&aaa=bbb"。这样的话,在Controller里截获然后再去取这个html就很笨了。不如就不截获它,在web.xml里绕开能够和”/FCKeditor/editor/fckeditor.html”匹配的pattern。
不过,这样的话可能会导致一些安全问题,FCKeditor能绕开的请求,别有用心的人也能绕的开了~~~最乐观的预计也是对于错误的请求如何收拾~