I wrote a little servlet that I need to deploy with tomcat. My server is tomcat 6. I first tried just dragging the war file and it unpacked, put I can't access the url (404 error). Then I even deleted the deploy and tried using the tomcat manager. When I click deploy is says 'OK' but doesn't show up in the list of applications deployed.
I used Eclipse (ganymede) to create the war file. The unpacked directory structure looks good. I am running on localhost:8080. Here is my web.xml. Perhaps there is something wrong here?
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<servlet>
<servlet-name>Auth</servlet-name>
<servlet-class>serv.Authenticate</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Auth</servlet-name>
<url-pattern>/authenticate</url-pattern>
</servlet-mapping>
</web-app>
I've read that maybe I need to do something to server.xml. But I looked around in there and there are no entries for any of tomcat's default web apps. How do I register my app so that tomcat serves it up like the others?
The web.xml look good but it is impossible to know why you are getting a 404 without knowing more about your environment.
The problem might be that the servlet is not loaded or if it is being loaded, that the servlet cannot find the URL.
To see if your servlet is being loaded add a log statement (System.out will do) to the init method of the servlet. Add the following line to your servlet element as well so that the servlet will not load on demand but at startup:
<load-on-startup>0</load-on-startup>
Then you can check that the servlet is being recognized and loaded.
Then add a log statement to the doGet/doPost etc methods to output the .getPathInfo of the request object. It might help to add a wildcard to the servlet mapping as well just to test:
<url-pattern>/authenticate/*</url-pattern>
Related
I'm using Spring MVC (Version 4.1) on Tomcat 8, and am desperately trying to make the file upload functionality work. Currently, I have a controller configured like this:
#RequestMapping(value={"/TestCase/Upload"}, method=RequestMethod.POST)
#ResponseBody
public ResponseEntity<String> uploadFile(HttpServletRequest request,
#RequestParam("file") MultipartFile file) {
System.out.println("Hit this location.");
return new ResponseEntity("Success");
}
My web.xml has the appropriate server configuration:
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
<!-- Configuration for file upload (configuring Multipart file) -->
<multipart-config>
<location>/tmp</location>
<max-file-size>500000</max-file-size>
<max-request-size>505000</max-request-size>
<file-size-threshold>10485</file-size-threshold>
</multipart-config>
</servlet>
And finally, my Spring xml configuration file has the necessary resolver specified:
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="500000" />
</bean>
The Apache commons-fileupload JAR is on the classpath.
I have used this approach successfully in the past on non-Tomcat servers, but now the application isn't working - but it's failing quietly. The response has a status code of 200, but nothing inside of the file upload controller method is executed. There are no exceptions thrown in the server logs, and the only way I can get the controller method to print anything out is if I remove the "Multipart" parameter entirely. At first I thought that the controller method wasn't being hit at all, but if I change the URL mapping, then the calling code throws a 404 - so it is definitely hitting the correct mapping/method - it's just that nothing inside of the method is executing (with no exceptions thrown!)
What am I doing wrong?
It turns out Spring MVC will hide noClassDef's from the console when booting itself up. The issue was that apache-commons-io.jar was missing on the classpath. Including that JAR caused everything to work properly.
So in the future if Spring is quietly misbehaving - check to ensure all necessary libraries are explicitly included, because it certainly won't tell you!
I am using Spring MVC framework for writing a web application. The first step is to modify the web.xml to make entry for the dispatcher servlet.
The snippet of the web.xml which has this change:
<servlet>
<servlet-name>MediumScaleProject</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<servlet-mapping>
<servlet-name>MediumScaleProject</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
I have following questions:
1) Does this mean anything with respect to context root has to go through this servlet mapping? (assume context root for this web application is /contextroot)
2) I want to capture user details in userDetails.html; with the above arrangement it is not working, that is if I access like this: /contextroot/userDetails.html; it is giving HTTP 404 error. What is the best strategy for handling these kind of scenarios?
If you want to make a project with the use of Spring MVC framework, you will need the Model, View and Controller.
yes everything will pass through
you better start to implement the MVC-idea
I have a web.xml file with (among other things) a servlet that defines an init-param to specify the contextConfigLocation, but the param-value is BLANK?
Why is the developer doing this. I can't for the life of me find anything in the documentations for Spring 3.X that tells me what effect this has.
<servlet>
<servlet-name>restservices</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
By default the DispatcherServlet will load a xml file named [servlet-name]-servlet.xml.
This is when no init-param named contextConfigLocation is defined.
However in your case there is an init-param named contextConfigLocation defined, which tells the DispatcherServlet to load nothing but only delegate to the parent context (the one loaded by the ContextLoaderListener).
So in short there is a difference between no init-param defined or an empty init-param.
See also https://jira.springsource.org/browse/SPR-4746.
it just because the developer had nothing to declare in the servlet configuration.
he had maybe defined all what he needs in the root context.
Ah. Generally, the dispatcher servlet would follow the convention of searching for servlet-name - servlet.xml to load the WebAppContext.
It might be (and this is just guess work because i dont know your config) that there already is a file restservices-servlet.xml which is
loaded using the ContextLoaderListener
Or imported in your applicationContext.xml ( or its equivalent)
Or isnt needed, because all the beans for the Controller/ViewResolver
are configured in your applicationContext.xml
Typically, the DispatcherServlet config (WebappContext) should contain the Controller/ViewResolver bean definitions.
I've been configuring XPM (Tridion 2012 UI Update) on a JSP development site. It's an all-in-one package, with Content Manager, Databases and Staging on the same server for development purposes.
I've made the following configurations:
Defined Staging Web App (called JSPStaging and set to a host header of jspstaging.project.dev), which receives content and places this content in its own folder from the HTTPUpload Web App, which is defined in the Publication Target in the CME
I've added the Java Session Preview Webservice (called cd_preview_webservice)
Currently my sites are being run by Tomcat 7, and IIS 7.5 is used for routing requests to port 8080 (Tomcat) which handles jspstaging.project.dev.
I know this is hardly an ideal situation, but I have to make do.
The problem at hand:
I've currently successfully implemented XPM (or at least, the dashboard, the ability to edit components and save those)
However, as soon as you want to update the page, it sometimes refreshes and it sometimes returns an error:
The remote server returned an error: (404) Not Found.
This is an (orange) Tridion Message. I'm not entirely sure the 404 error described above is the same as the one documented on the SDL Live Content.
This is the error in the Event Viewer on the server:
Unable to update the changes using OData Service. The remote server returned an error: (404) Not Found. Component: Tridion.SiteEdit.FastTrackPublishing Errorcode: 1003 User: NT AUTHORITY\NETWORK SERVICE
As such, I'm following this downright amazing blogpost Albert Romkes wrote, and at point 2 in his article he mentions navigating to odata.svc. I cannot seem to find the file anywhere on my staging or session preview web apps. I've installed .NET applications of Tridion before, and while the .NET app on the installation media (among other files) has an acces_token and a odata.svc file, I noticed that the JAVA install of the webservice of session preview does not have these files. However, later in the install guide you need those files to set up publishing.
When I follow the JSP site part and fill in the fields on the Session Preview Tab of the Publication Target, I cannot navigate to this odata url on the server itself, which is now
http://localhost:8080/cd_preview_webservice/cdws/odata.svc/
The Tridion Logging does not say something is wrong, for staging AND for session preview web app, as well as the Tomcat logs. They even say OData is working just fine, as far as I can tell...
If I cannot navigate to the url posted above, does this mean something is wrong, or that the 404 error is because of that?
EDIT
my web.xml of staging:
<?xml version="1.0" encoding="UTF-8"?>
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
Content Delivery Web service
<jsp-config>
<taglib>
<taglib-uri>cd_tags</taglib-uri>
<taglib-location>/WEB-INF/lib/cd_tags.tld</taglib-location>
</taglib>
</jsp-config>
<listener>
<listener-class>
com.tridion.storage.persistence.session.SessionManagementContextListener
</listener-class>
</listener>
<!--
OData and linking Web service
-->
<servlet>
<servlet-name>Content Delivery Web service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
<param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.classnames</param-name>
<param-value>com.tridion.webservices.odata.ODataWebservice;com.tridion.webservices.linking.LinkingService;com.tridion.webservices.odata.JAXBContextResolver</param-value>
</init-param>
</servlet>
<filter>
<filter-name>Ambient Data Framework</filter-name>
<filter-class>com.tridion.ambientdata.web.AmbientDataServletFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Ambient Data Framework</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet-mapping>
<servlet-name>Content Delivery Web service</servlet-name>
<url-pattern>/cdws/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>Page Content Filter</filter-name>
<filter-class>com.tridion.preview.web.PageContentFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Page Content Filter</filter-name>
<url-pattern>/cdws/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>com.tridion.webservices.odata.ODataContextListener</listener-class>
</listener>
<filter>
<filter-name>Binary Content Filter</filter-name>
<filter-class>com.tridion.preview.web.BinaryContentFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Binary Content Filter</filter-name>
<url-pattern>/Images/*</url-pattern>
</filter-mapping>
You mentioned that you've added the cd_preview_webservice, however, the error message dictates that it's not working. On the Java side, you won't see the odata.svc file as this url is handled by one of the classes within the jars, so don't worry about that.
In your Tomcat console, does it show that the app has been deployed/started without error?
Also the URL that you mention "/cd_preview_webservice/cdws/odata.svc/" has a "/cdws/" in it. This seems a bit irregular. Typically the url is "/cd_preview_webservice/odata.svc". What is does your web.xml look like?
This question already has answers here:
Servlet returns "HTTP Status 404 The requested resource (/servlet) is not available"
(19 answers)
Closed 6 years ago.
I have a servlet register in class p1. I have a JSP jsp1.jsp. I run JSP file and see it, but when I try to apply to the servlet, Tomcat shows an error:
HTTP Status 404
The requested resource (/omgtuk/Register) is not available.
Servlet:
#WebServlet("/register")
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>omgtuk</display-name>
<servlet>
<description></description>
<display-name>register</display-name>
<servlet-name>register</servlet-name>
<servlet-class>p1.register</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>register</servlet-name>
<url-pattern>/register</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>jsp1.jsp</welcome-file>
</welcome-file-list>
</web-app>
I'm using Eclipse.
The requested resource (/omgtuk/Register) is not available.
This simply means that the servlet isn't listening on an URL pattern of /Register. In other words, you don't have a #WebServlet("/Register").
In your particular case, you made a case mistake in the URL. URLs are case sensitive. You're calling /Register, but your servlet is listening on /register. Fix your form action accordingly.
So, it should not look like this:
<form action="Register">
But it should look like this:
<form action="register">
Or this, which is more robust in case you happen to move around JSPs when you're bored:
<form action="${pageContext.request.contextPath}/register">
Unrelated to the concrete problem, please note that you registered the servlet via both a #WebServlet annotation on the class and a <servlet> entry in web.xml. This is not right. You should use the one or the other. The #WebServlet is the new way of registering servlets since Servlet 3.0 (Java EE 6) and the <servlet> is the old way of registering servlets.
Just get rid of the whole <servlet> and <servlet-mapping> in web.xml. You don't need to specify both. Make sure that you're reading up to date books/tutorials. Servlet 3.0 exist since December 2009 already.
Another detail is that p1 is not a class, it's a package. I'd warmly recommend to invest a bit more time in learning basic Java before diving into Java EE.
See also:
Our servlets wiki page