我正在使用spring mvc 4并尝试将一个简单map的函数返回到ajax - 从我的控制器到jsp文件.
控制器:
@RequestMapping(value = "/ajaxtest", method = RequestMethod.GET)
public @ResponseBody
Map<String, String> myTest() {
System.out.println("------------------------------------test");
Map<String,String> myMap = new HashMap<String, String>();
myMap.put("a", "1");
myMap.put("b", "2");
return myMap;
}
Run Code Online (Sandbox Code Playgroud)
来自jsp文件的Ajax:
function testAjax() {
$.ajax({
url : '../../ajaxtest.html',
dataType: "json",
contentType: "application/json;charset=utf-8",
success : function(data) {
alert("1");
alert(data);
}
});
}
Run Code Online (Sandbox Code Playgroud)
但我没有得到任何警报,只是错误HTTP/1.1 406 Not Acceptable.
但是,更改代码以返回一个简单的字符串工作正常.控制器:
@RequestMapping(value = "/ajaxtest", method = RequestMethod.GET)
public @ResponseBody
String myTest() {
System.out.println("------------------------------------test");
return "hello";
}
Run Code Online (Sandbox Code Playgroud)
阿贾克斯:
function testAjax() …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 spring mvc 4 和 apache tomcat 7 (在 firefox 中)添加 favicon.ico。我检查了许多解决方案,但似乎没有一个有效。
网络.xml:
<mime-mapping>
<extension>ico</extension>
<mime-type>image/x-icon</mime-type>
</mime-mapping>
Run Code Online (Sandbox Code Playgroud)
mvc-core-config.xml:
<mvc:default-servlet-handler/>
<!-- <mvc:resources mapping="/resources/**" location="/resources/css" /> -->
<mvc:resources location="/favicon.ico" mapping="/favicon.ico" />
Run Code Online (Sandbox Code Playgroud)
jsp:
<link href="MYPROJECT/favicon.ico" rel="icon" type="image/x-icon">
Run Code Online (Sandbox Code Playgroud)
(我也尝试过没有 MYPROJECT 和其他变体......)。
我将 favicon.ico 文件放在 webapps 下(也在其他文件夹中尝试过)。
加载页面时,没有显示任何图标。
注意:我尝试直接加载图标http://localhost:8080/MYPROJECT/favicon.ico,但收到以下错误消息:the image 'http://localhost:8080/MYPROJECT/favicon.ico' cannot be displayed because it contains errors。我下载了其他 favicon.ico,但图标看起来已损坏。
在 Firefox 中检查元素时,我不会调用 favicon.ico。
有什么建议吗?
更新: 在我的 Eclipse 控制台中我看到:
查找路径 / 15:48:05.622 [http-bio-8080-exec-6] 的处理程序方法 DEBUG oswsmmaRequestMappingHandlerMapping - 未找到 [/] 15:48:05.622 [http-bio-8080-exec-6] …
我有一个名为'act'的隐藏参数,它应该传递一个值'load','save'按下提交按钮.
问题是按下提交按钮后按下F5(刷新)按钮,因为网址已经包含'&act = save',因此F5上的prssing实际上再次传递(到cgi)'save'值(并执行保存操作)甚至我没有按下提交按钮.
问题是如何在按下重新打印按钮时阻止发送'&act = save'?
谢谢
谢谢你们所有人,但提交按钮是一个"保存"按钮 - 意味着我希望让用户能够保存更多的保存按钮,所以不要离开页面.由于这个原因,我不认为会话可能有助于区分第二次保存或第一次刷新.
我试图检查是否可以使用"isReachable"方法访问某些主机.
line 113: oaiBaseURL = "http://www.cnn.com";//////////////////////////////////////
line 114: boolean res = InetAddress.getByName(oaiBaseURL).isReachable(10000);
line 115: System.out.println("------reachable:"+res);
Run Code Online (Sandbox Code Playgroud)
并获取以下错误消息(在eclipse中):
java.net.UnknownHostException: http://www.cnn.com
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(Unknown Source)
at java.net.InetAddress.getAddressFromNameService(Unknown Source)
at java.net.InetAddress.getAllByName0(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at java.net.InetAddress.getByName(Unknown Source)
at com.irWizard.web.validator.WizardValidator.validateForm(WizardValidator.java:114)
Run Code Online (Sandbox Code Playgroud)
有谁知道这个错误可能是什么原因?
提前致谢!
在我在eclipse kepler工作期间,它崩溃了.
现在我无法在请求的工作空间上打开eclipse(在其他工作空间上它打开很好).
选择工作区后,我收到一条弹出消息:
An error has occurred. see the log file. ...WORKSPACE/.metadata/.log
打开日志文件:
!SESSION 2015-03-19 17:10:55.171 -----------------------------------------------
eclipse.buildId=4.3.0.I20130605-2000
java.version=1.7.0_71
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Framework arguments: -product org.eclipse.epp.package.jee.product
Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.jee.product
!ENTRY org.eclipse.core.resources 2 10035 2015-03-19 17:10:58.594
!MESSAGE The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes.
!ENTRY org.eclipse.osgi 4 0 2015-03-19 17:10:58.910
!MESSAGE An error occurred while automatically activating bundle org.eclipse.core.resources (82). …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的哈希值的哈希值:
%hash = {
car => {
'10' => 'y',
'11' => 'y',
'12' => 'y',
'13' => 'y'
},
bus => {
'10' => 'y',
'11' => 'y',
'12' => 'y',
'13' => 'y'
},
tr => {
'10' => 'y',
'11' => 'y',
'12' => 'y',
'13' => 'y'
}
}
Run Code Online (Sandbox Code Playgroud)
我如何在 PERL 中打印这个哈希值(使用 Dumper),其中每个部分的键按上述顺序排序(10,11,12,13,14...)?
提前致谢,
三木