<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<%
String contextpath = request.getContextPath();
System.out.println(contextpath);
%>
<title>My JSP 'test.jsp' starting page</title>
<script>
var ajax;
function insertCell(){
var url = "<%=contextpath%>/get"
if(window.XMLHttpRequest){
ajax = new XMLHttpRequest();
if(ajax.overrideMimeType){
ajax.overrideMimeType('text/xml');
}
}else if(window.ActiveXObject){
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}
ajax.open("GET",url,true);
ajax.onreadystatechange = processRequest;
ajax.send();
}
function processRequest(){
if(ajax.readyState == 4){
//alert("1111"+ajax.status);
//alert(ajax.status);
if(ajax.status == 200){
var response = ajax.responseText;
insertReportList(response);
}
}
}
function insertReportList(str) {
var tr = "";
var td = "";
tr = mytable.insertRow(mytable.rows.length);
td = tr.insertCell(0);
td.innerHTML = str;
}
</script>
</head>
<body>
This is my JSP page. <br>
<input type = button name = "test" value = "click" onclick = insertCell()>
<table id = mytable>
<tr><td>Description</td></tr>
</table>
</body>
</html>