I'm building a web app for store scientific publications. I've used MySQL, JSP, jQuery and JAVA.
I have a form inside a JSP page, like this:
<form method="get">
<input type="text" id="code">
<button onclick="request()">Search</button>
</form>
The function request() is:
function request() {
var code = $('#code').val();
var data='code='+code;
$.ajax({
url: "Servlet",
type: "GET",
data: data,
success: function(){
alert("success");
},
error:function(){
alert("failure");
}
});
};
The Servlet do some stuff and then save the resultset of query in the request object and forward the result on the index like this
request.setAttribute("result", resultSet);
RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/index.jsp");
dispatcher.forward(request, response);
The index.jsp contains:
<% if(request.getAttribute("result")!=null){ %>
<jsp:include page="table.jsp" />
<%}%>
check if the result set is already filled, then include table.jsp, the page scan the resultset and put the values in a table.
This code doesn't work, someone can help me? 1- The query runs correctly 2- jQuery is called correctly
but the
if(request.getAttribute("result"))
is always null.