javascript 无法加载资源:net::ERR_TOO_MANY_REDIRECTS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27664376/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed to load resource: net::ERR_TOO_MANY_REDIRECTS
提问by Marcia Yudkin
I just started learning Backbone JS. In below code, iam just trying to call url todos/1expecting to get json data. Instead iam getting error in console as "Failed to load resource: net::ERR_TOO_MANY_REDIRECTS" I didnt understood why index.jsp keep redirecting many times itself.
我刚开始学习 Backbone JS。在下面的代码中,我只是试图调用 url todos/1期望获得 json 数据。相反,我在控制台中收到错误消息,因为“无法加载资源:net::ERR_TOO_MANY_REDIRECTS”我不明白为什么 index.jsp 本身会多次重定向。
Could anyone please explain me what went wrong and also solution too
任何人都可以请解释我出了什么问题以及解决方案
test.jsp
测试.jsp
<html>
<head>
<script
src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script
src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js"></script>
<script
src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"></script>
<script type="text/javascript">
var myname;
var myjson;
//WAY ONE
$.getJSON("todos/1", alertUser);
function alertUser(data) {
console.log(data.id);
id = data.id;
alert(id);
var TodoItem = Backbone.Model.extend({});
var todoItem = new TodoItem(data);
var TodoView = Backbone.View.extend({
render: function(){
var html = '<h3>' + this.model.get('description') + '</h3>';
$(this.el).html(html);
}});
var todoView = new TodoView({model : todoItem});
todoView.render();
console.log(todoView.el);
}
</script>
</head>
<body>
</body>
</html>
index.jsp
索引.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="org.json.JSONObject" %>
<%
JSONObject obj = new JSONObject();
obj.put("description", "pick up milk");
obj.put("status", "incomplete");
obj.put("id", 1);
response.setContentType("application/json");
out.print(obj);
%>
MyServlet.java
我的Servlet.java
public class MyServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public MyServlet() {
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.sendRedirect("index.jsp");
}
}
web.xml
网页.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/todos/*</url-pattern>
</servlet-mapping>
</web-app>
采纳答案by Marcia Yudkin
I found a solution for my above problem. Hope it might somebody helps.
我找到了解决上述问题的方法。希望它可能有人帮助。
In MyServlet.JavaI need to change below
在MyServlet.Java 中,我需要在下面更改
response.sendRedirect("index.jsp");
to
到
response.sendRedirect("/MyProj/index.jsp");