Enunciado do exercicio:
Elabore um documento HTML que leia dois números inteiros, constituindo um intervalo inicial e final. Os
números do intervalo devem ser validados no clientee no servidor. A validação dos números no servidor
deve ser feita através de uma sub-rotina JSP. O documento HTML deve possuir um botão ?Calcular? que
requisite uma página JSP. Essa página deve receber os números digitados e calcular, através de uma subrotina JSP,
a soma de todos os números do intervalo. O valor da soma deve ser enviado ao navegador
cliente como resposta e inserido em uma caixa de texto na página atual (documento HTML que requisitou a
página JSP) do cliente através da tecnologia DOM.
minha dúvida e so o seguinte...
eu quero um método ou seila oque
para pegar o valor que o jsp retornou atráves de javascript/dom
para eu poder setar ele no text que pedio
obs: ate consegui mas o resultado não foi o esperado.
meus fontes
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script language = "javascript" src = "Exercicio12.js"></script>
</head>
<body>
<form name = "formulario" id = "formulario" method = "get">
<label for = "inicio">inicio: </label>
<input type = "text" name = "inicio" id = "inicio" />
<br />
<label for = "fim">fim: </label>
<input type = "text" name = "fim" id = "fim" />
<br />
<input type = "button" value = "Calcular" onclick = "somatorio();"/>
<br />
<input type = "text" id = "soma"/>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
int inicio = Integer.parseInt(request.getParameter("inicioo"));
//int fim = Integer.parseInt(request.getParameter("fimm"));
//int soma = inicio + fim;
out.println(inicio);
%>
</body>
</html>
var req;
function somatorio() {
var inicio = document.getElementById("inicio");
//var fim = document.getElementById("fim");
var url = "Exercicio12.jsp?inicioo=" + escape(inicio.value); //+ "&fimm=" + escape(fim.value);
if (window.XMLHttpRequest) { // requisição assincrona
req = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
req.open("GET", url, true); // true requisição assincrona, se false ela é sincrona.
req.onreadystatechange = callback; // quando pronto muda o estado
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
req.send(null);
}
function callback() {
if (req.readyState == 4) {
if (req.status == 200) {
var soma = document.getElementById("soma");
soma.value = req.responseText;
}
else
alert("Status: " + req.statusText);
}
}
function clear() {
var chave = document.getElementById("inicio");
chave.value = "";
}
retorno dele para o text
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Insert title here</title></head><body> 11</body></html>
já tentei eliminar esse