gpt4 book ai didi

javascript - 无法加载资源:net::ERR_TOO_MANY_REDIRECTS

转载 作者:行者123 更新时间:2023-12-01 05:45:00 28 4
gpt4 key购买 nike

我刚刚开始学习 Backbone JS。在下面的代码中,iam 只是尝试调用 url todos/1 期望获取 json 数据。相反,我在控制台中收到错误“无法加载资源:net::ERR_TOO_MANY_REDIRECTS”,我不明白为什么 index.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

<%@ 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

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 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>

最佳答案

我找到了解决上述问题的方法。希望有人能帮忙。

MyServlet.Java中,我需要更改下面

response.sendRedirect("index.jsp");

response.sendRedirect("/MyProj/index.jsp");

关于javascript - 无法加载资源:net::ERR_TOO_MANY_REDIRECTS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27664376/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com