I created a spring MVC project, with a controller class having request mapping methods but when I run the project on server it gives me a 404 error (Requested resource not found)
Attached below are the screenshots of my web.xml, idm-servlet.xml and the controller class files.
After running the project, the URL remains the same instead of getting changed due to mapping.
In the url-pattern of idm servlet you listen to any HTTP requests which ends with ".do"
While your request mapping contains "/home"
I would do change the mapping to "/home.do"
Please add in web.xml:
<welcome-file-list>
<welcome-file>home</welcome-file>
</welcome-file-list>
It should help.
Try to change DispatcherServlet mapping form *.do to /. Also I think you miss some dependencies(jars).
Related
I'm not sure how to start on this, but I currently have a simple application that has a home page url of
localhost:8080/projectName/homePage.jsp
However, I'd like it so that
localhost:8080/projectName/
OR
localhost:8080/projectName
sends me to the homePage.jsp.
I've read about an index.jsp that was created by eclipse in other projects, but it seems like that hasn't been done for me - do I need to create this? I'm not using a web.xml, and am instead relying on #WebServlet to do wiring.
2 ways to do this.
1. Add an entry in web.xml as follows
<welcome-file-list>
<welcome-file>homepage.jsp</welcome-file>
</welcome-file-list>
2. create an index.jsp file in your WebContent folder and forward the request to homePage.jsp
According to the following post there is no such way possible with annotation:
Servlet 3.0 annotations <welcome-file>
Can I make the welcome-file of the website to be a servlet ? If yes , how ? I was trying something like :
<welcome-file-list>
<welcome-file>FilterForwarded</welcome-file>
</welcome-file-list>
<!-- FilterForwarded is a servlet -->
While deploying I do not see any error but when I try to open the website abc.com I get a message from the browser that it is unable to connect to this website.Why is it so ?
I want when anyone visits the website,I should be able to store the client's public IP. To do this I wrote a Filter which after taking the IP , passed it to the servlet (from there I could update the logs). After storing the IP , client be automatically redirected to index.jsp. Is there any way to achieve this ?
EDIT :
<servlet-mapping>
<servlet-name>FilterForwarded</servlet-name>
<url-pattern>/FilterForwarded</url-pattern>
</servlet-mapping>
This is the mapping defined in web.xml . When I use /FilterForwarded in welcome-file I get this message when I try to deploy : Bad configuration: Welcome files must be relative paths: /FilterForwarded
From the logs :
com.google.apphosting.utils.config.AppEngineConfigException: Welcome files must be relative paths: /FilterForwarded
at com.google.apphosting.utils.config.WebXml.validate(WebXml.java:125)
at com.google.appengine.tools.admin.Application.<init>(Application.java:150)
at com.google.appengine.tools.admin.Application.readApplication(Application.java:225)
at com.google.appengine.tools.admin.AppCfg.<init>(AppCfg.java:145)
at com.google.appengine.tools.admin.AppCfg.<init>(AppCfg.java:69)
at com.google.appengine.tools.admin.AppCfg.main(AppCfg.java:65)
If you map the filter to /* you should be able to intercept all requests and then log the IP from there.
Or is your requirement to only log Client IP for the landing page?
If so, you could change the default servlet for the Servlet container, but bear in mind this will change the default servlet for all requests that do not match mappings in your web.xml.
<servlet-mapping>
<servlet-name>FilterForwarded</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
A more complex, but potentially better solution, is to front your Java web container with a web server and use rewrite rules to proxy to your backend Servlets. This way will mean that you can control the Servlet that is accessed for your landing page without overriding the default servlet for all non-matching requests. This might be overkill for your problem though.
I have a tomcat 7 application which I can get requests from external sources.
Most of them call my request like this:
http://localhost:8080/MyWeb/exRequest
and I build servlet with URL pattern inside MyWeb app.
However, one external source must send the request like this:
http://localhost:8080/
and in the body:
<xml name="test" />
Since I don't want to declare a general servlel (like tomcat default) since it means that any request will need to go through my servlet, I thought to change index.jsp of ROOT to redirect to my servlet.
Is it the best option?
Is there an option to create a default servlet that will be invoked only if there is a special parameter in the body?
EDITED
Please note that I get the requests to localhost:8080 and not localhost:8080/MyWeb - it's general to tomcat and not to a specific web app
You can't choose a servlet to invoke based on the request body, but you can set a servlet as the "welcome-file" in your web.xml.
<servlet>
<servlet-name>index</servlet-name>
<servlet-class>com.y.MyWelcomeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>index</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index</welcome-file>
</welcome-file-list>
If you want to preserve the "welcome" function of some existing index.jsp, your servlet could forward requests without the correct XML in the body to an index.jsp file located under the WEB-INF directory.
No, but you can create a Filter and forward/redirect to a specific servlet whenever the request meets certain conditions.
If using servlet 3.0 map it with #WebFilter, otherwise use web.xml and <filter> + <filter-mapping>. You should map it be executed before the default servlet.
Hey all, This is my first question here!
I'm trying to setup custom error pages in my JBoss RESTful web service. I'm starting with the 400 error, so in my web.xml I've added
<error-page>
<error-code>400</error-code>
<location>/400.html</location>
</error-page>
and I've placed 400.html at the root of my war file (I've also tried placing it at the root of WEB-INF). Unfortunately, I keep getting 404's when I'm supposed to get 400's, presumably because JBoss can't seem to find 400.html. Any ideas what I'm doing wrong?
Might it be because my servlets are mapped to the root?
<servlet-mapping>
<servlet-name>api</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
if so, what are the alternatives?
Thanks!
For posterity: I was able to finally get this working by redirecting errors to a page that Spring MVC had a controller for. The controller just returned a null ModelAndView. Because it was a RESTful service, I really didn't need to have any HTML emitted anyway.
I have a JavaEE 1.4 web application running on WebSphere Application Server 6.0. In web.xml, there is a servlet configured to intercept all server requests:
<servlet-mapping>
<servlet-name>name</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
This works fine until I try to request something ending with *.jsp. In this case, server tries to find JSP with this name and fails with the error:
java.io.FileNotFoundException: JSPG0036E: Failed to find resource /cfvct/search_criteria.jsp
at com.ibm.ws.jsp.webcontainerext.JSPExtensionProcessor.findWrapper(JSPExtensionProcessor.java:279)
at com.ibm.ws.jsp.webcontainerext.JSPExtensionProcessor.handleRequest(JSPExtensionProcessor.java:261)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3226)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:253)
at com.ibm.ws.webcontainer.VirtualHost.handleRequest(VirtualHost.java:229)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1970)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:120)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:434)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:373)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:253)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminaters(NewConnectionInitialReadCallback.java:207)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:109)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:566)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java:619)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:952)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1039)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1475)
I need to have this request processed by the servlet, but seems server uses some JSPExtensionProcessor to process all paths ending with .jsp. Is there any way to change this behaviour?
Yes, you'll need to map your servlet to *.jsp in order to get *.jsp support redirected to your servlet.
<servlet-mapping>
<servlet-name>name</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
It is normally a bad idea to have jsps accessible directly, however. Placing them in WEB-INF in some directory, then mapping an appropriate url (.do, .action, etc) to a servlet that then redirects internally to that JSP is the better practice.
So instead of typing thisUrl.jsp, the user would type thisUrl.do or thisUrl.action, and it would then get hit by the servlet to redirect to thisUrl.jsp.