i have a web project , all i wanna do is to send a String to the servlet then return the same string to the jsp Page(formList.jsp) and display it:
javascript code to send the String :
$(document).ready(function(){
$('#submit').click(function() {
var value = $('#val').val();
$.ajax({
type:'POST',
data:{value:value},
url:'FormList',
success:function(result){
$('#res').text(result);
}
});
});
});
'FormList' Servlet doPost :
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/plain");
String value = request.getParameter("value");
response.getWriter().print(value);
}
web.xml (located in WEB-INF):
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<servlet-name>FormList</servlet-name>
<servlet-class>FormList</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FormList</servlet-name>
<url-pattern>/FormList</url-pattern>
</servlet-mapping>
</web-app>
but the when i click the submit button, the result i get is the formList.jsp page HTML source : (<!DOCTYPE html PUBLIC ....
)
*i'm overriding the service method in servlet to initialize the formList.jsp
i think that doPost is not executed at all any help please