jquery - Configuring a Java HTTP servlet in Netbeans 7.3 -
i've upgraded netbeans 7.3, , quite don't of project configuration , interface. example, once used see source packages java classes, i'm not able see them in file panel. have package called batchutility containing http servlet called batchqueryservlet.
i have post json batchqueryservlet via jquery.ajax() function , i'm not able map servlet.
since netbeans 7.3 doesn't ship config file, i've created 1 myself clicking on web-inf folder>new>web.xml file , wrote follows:
<web-app 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" version="3.0"> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>batchqueryservlet</servlet-name> <servlet-class>/batchutility.batchqueryservlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>batchqueryservlet</servlet-name> <url-pattern>/batchqueryservlet</url-pattern> </servlet-mapping> </web-app> but still, when issuing request, 404 error:
$.ajax({ url: "/batchqueryservlet", contenttype: 'application/json', data: json, accept: "text/html", success: function(data, textstatus, jqxhr) { alert(data); }, type: "post" }); now, i'm pretty sure doesn't find class because if call servlet name classnotfound exception. how fix that? (a quick , dirty solution using jsp i'd rather not it).
ps: use version 7.0.34 of tomcat.
edit problem should use proper src/java path storing .java classes instead of plain folder (this reason couldn't see packages). i've fixed it. anyway time!
you have leading slash in
<servlet-class>/batchutility.batchqueryservlet</servlet-class> remove , things should work.
change ajax url: either "batchqueryservlet" or "/web-app-name/batchqueryservlet"
edit:
once deployed web application's folder structure should like: (/ indicates directory)
tomcat-home/ |- webapps/ |- batchwebapp/ //<-- context-root (web-app's name) |- *.html, *.jsp etc. |- web-inf/ |- web.xml |- lib/ |- *.jar files |- classes/ //<-- servlets go here |- batchutility/ //<-- required package/folder structure |- batchqueryservlet.class if you're using ide (like eclipse) same you.
Comments
Post a Comment