java로 웹 응용 프로그램을 만들고 있습니다. 클라이언트 측에서는 Java 서버 페이지에서 작성된 tsv 파일에 저장된 일부 데이터를 표시하는 막 대형 차트가 있습니다. 버튼을 클릭하면 서버가 파일의 이러한 데이터를 업데이트합니다. 이제 새로 고침 된 데이터를 읽고 싶지만 이전 데이터는 가져옵니다. 브라우저가 파일을 캐시하여 변경된 파일을 가져올 수없는 것 같습니다.서버에서 생성 한 파일에서 클라이언트의 업데이트 된 데이터를 읽습니다. JSP
이 내 서블릿 코드 :
public class GetDataServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
private User user;
Utility utility;
public void init() throws ServletException {
reset();
}
public void doGet (HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
PrintWriter out = response.getWriter();
user.getProfile().get(0).setWeigth(user.getProfile().get(0).getWeigth()+0.03);
user.getProfile().get(1).setWeigth(user.getProfile().get(1).getWeigth()+0.02);
user.getProfile().get(5).setWeigth(user.getProfile().get(5).getWeigth()+0.01);
utility.createTsvFile(user, "/usr/local/apache-tomcat-7.0.50/webapps/Visualizer/data.tsv");
String message = String.format("data.tsv");
i++;
out.print(message);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if(request.getParameter("reset").compareTo("yes")==0)
reset();
}
private void reset(){
List<Concept> children = new ArrayList<Concept>();
Concept food = new Concept();
food.setWeigth(0.10);
food.setLabel("food");
food.setColor("#98abc5");
Concept dish = new Concept();
dish.setWeigth(0.08);
dish.setLabel("dish");
dish.setParent(food);
dish.setColor("#8a89a6");
Concept cuisine = new Concept();
cuisine.setWeigth(0.06);
cuisine.setLabel("cuisine");
cuisine.setParent(food);
cuisine.setColor("#8a89a6");
children.add(dish);
children.add(cuisine);
food.setChildren(children);
children.clear();
Concept pizza = new Concept();
pizza.setWeigth(0.05);
pizza.setLabel("pizza");
pizza.setParent(dish);
pizza.setColor("#6b486b");
Concept spaghetti = new Concept();
spaghetti.setWeigth(0.05);
spaghetti.setLabel("spaghetti");
spaghetti.setParent(dish);
spaghetti.setColor("#6b486b");
Concept sushi = new Concept();
sushi.setWeigth(0.06);
sushi.setLabel("sushi");
sushi.setParent(dish);
sushi.setColor("#6b486b");
children.add(pizza);
children.add(spaghetti);
children.add(sushi);
dish.setChildren(children);
List<Concept> profile = new ArrayList<Concept>();
profile.add(food);
profile.add(dish);
profile.add(cuisine);
profile.add(pizza);
profile.add(spaghetti);
profile.add(sushi);
user = new User("mario", profile);
utility = new Utility("");
}
}
이 서블릿 호출하는 자바 스크립트 코드 :
<meta http-equiv="Cache-control" content="no-cache">
: 나는이를 넣어 한 HTML 페이지에서
function ajaxSyncRequest(reqURL) {
//Creating a new XMLHttpRequest object
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest(); //for IE7+, Firefox, Chrome, Opera, Safari
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); //for IE6, IE5
}
//Create a asynchronous GET request
xmlhttp.open("GET", reqURL, false);
xmlhttp.send(null);
//Execution blocked till server send the response
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
document.getElementById("message").innerHTML = xmlhttp.responseText;
update(xmlhttp.responseText);
//alert(xmlhttp.responseText);
} else {
alert('Something is wrong !!');
}
}
}
function update(file){
d3.tsv(file, function(error, data) {
......
을
하지만 작동하지 않습니다.
이 코드를 사용하면 파일 tsv의 데이터가 변경된 경우에도 처음 서블릿을 호출 할 때 정확한 데이터를 표시 할 수 있습니다.
파일에서 새로 고침 된 데이터를 읽는 가장 좋은 방법은 무엇입니까? 이 때문에 두 hings는
1
을 수행 할 수 있습니다처럼
http://stackoverflow.com/questions/1046966/whats-the- 캐시간에 차이점 - 최대 - 0 - 및 - no-cache – rickz
캐시 및 max-age = 0 재 시도 없음 시도했습니다. –
tsv 파일을 만든 다음 "data.tsv"를 브라우저에 출력하고 있습니다. 즉, 응답에서 tsv 파일을 반환하지 않습니다. 이게 니가 의도 한거야? – Taylor