Error-page not working (with pic) - java

I'm working in Eclipse+tomcat. My custom made static error page is not showing up in tomcat when i click on url for non-existing pages. generated-error.html has a simple img src="404_man.jpg" tag. But I keep getting the error page shown on the pic.
My servlet version is 3.0 if i view it from manifest.mf.

Have you tried the error definition for generic errors, not just 404.
/general-error.html
And are you sure tomcat is running on port 8080?
The error page does not look like Tomcat7's default 'cant find page' page.

Some browser like IE needs atleast 512 bytes of data to render. Otherwise it will not render the response. Try adding more content in your error page.
I believe you have very less content in your error page.
Mozilla will work without any problem in this kind of situation.

Related

Apache Tomcat - Display a custom error message like "You have typed an invalid url" instead of displaying "HTTP Status 404 – Not Found"

This below url with myWebAppName should be the only valid url that Tomcat should process.
https://hostname:port/myWebAppName
The above is working as expected.
Also , the invalid urls given in the below format i.e junk characters given after webappname, also displays the custom "404.html" as expected.
https://hostname:port/myWebAppName/xxxx
Solution Requested : If we provide wrong web application name , the Tomcat Error Page is getting displayed instead of custom error page.
i.e https://hostname:port/wrongmyWebAppName (or) https://hostname:port/abcd
Location of 404.html : Tomcat/webapps/myWebAppName/404.html
Please assist as early as possible. Would be highly obligued if this can be solved in web.xml itself , as I have already delivered war for test.
Thanks in Advance,
Ags
In your web.xml
<error-page>
<error-code>404</error-code>
<location>/NotFound.jsp</location>
</error-page>
Adding the following entry in Tomcat's server.xml file , restricts the version information getting displayed if the invalid webapp name is provided in URL.
(open tag) Valve className="org.apache.catalina.valves.ErrorReportValve" showReport="false" showServerInfo="false" (add close tag)
The above solution is needed for : Attackers provide invalid url and obtain the version information, and the vulnerabilities for that version are provided in the Tomcat Documentation,which might help attackers to hack sensible data passed across the web.

Tomcat 404 when using servlets

So I am currently trying to test a project whose facets I have changed, namely, I added a dynamic web component to it. In order to do so I decided to do a basic html form, and associated servlet with it.
However, when I try to run it I get a 404. Interestingly enough, a project I had which worked fine today is now also facing a similar issue. Though my practice servlet, which is used a template for everything else, does not have this issue.
the form follows this format:
<form action="myServlet">
<input type = "submit"/>
</form>
the servlet simply returns a writer.println("Hello World");
Error message:
HTTP Status 404 - /userName/LoginServlet
type Status report
message /userName/LoginServlet
description The requested resource is not available.
Apache Tomcat/8.0.38
Edit, and now the one servlet that worked also stopped working throwing the same error. If it helps, I am trying to run it from eclipse, by right clicking on my html page and then selecting for it to run on my server.
Problem was rather simple to hidden, since the name was refactored, the servlet mapping in eclipse did not show this. Deleting and recreating the servlet fixed it.
At least for now.

Add a servlet will disable all servlet

I'm new to JavaEE and I have a problem with java servlet.
I have a servlet works well. Then I want to add another one. However, once I added the second one, the first one no longer works and server always respond 404 without any content (Normally the 404 will return with a page, not it is just a white page)
There must be some problems with the second servlet and If I disable one line of code the first servlet works. However I haven't seen any error messages
Can someone tell me the reason of this and how can I debug the program. (I cannot debug the program because the request cannot map to the second servlet and no breakpoints work)
Thanks a lot.
Fallflame
UPDATE
Now it works, thanks to Danail Alexiev remind me that it is may be a configuration problem. I found an error that said "cannot convert the project to dynamic web 2.5" and I just do maven -> update project then it works.
Still cannot understand why.
This is the one line code that let all servlets don't works :
ServiceMetadata edm = odata.createServiceMetadata(new DemoEdmProvider(), new ArrayList<EdmxReference>());
all copied from Apache Olingo tutorial.

Getting blank page in spring application and after cleaning browser cache it works fine

I have created one spring application and it worked fine before one day but today I have made some changes and now I am running the application but when I click on any link (any action) it shows the blank page.
And if I clean the cache of the browser it works fine.
I haven't used any chache in application.
Don't understand what is the problem, is it with browser or with coding????
I think blank page is coming due to browser cache. As you have told that you have changed many things, so it might be like that browser is expecting few resources as per its cache records but you have already changed many things so it doesn't have any response to show.
You should configure the Error code 404 properly, so browser can simply show you the error that it is unable to find the resource.
<error-page> <error-code>404</error-code> <location>/WEB-INF/pages/404.jsp</location> </error-page>
After adding this in web.xml, application is working fine.
Thnak you Vineet Tyagi

How to Map home page to "root of application" in Java EE?

Set-Up-
I have a JSP - index.jsp and a servlet indexController. indexController forwards request to index.jsp. Execution of index.jsp without execution of indexController is not desired.
Requirements-
'www.mysite.com' should be served by indexController/index.jsp
Any request with invalid url should get redirected to 'www.mysite.com'.
'www.mysite.com/index.jsp' should get redirected to 'www.mysite.com'.
My Solution -
Map indexController to "/" - I read that this is overriding 'default servlet' and I want to avoid that.
Map 'index.jsp' in welcome-file-list: I don't need to explicitly map it science 'index.jsp' is there, it will be automatically taken as welcome file. Doing this doesn't execute indexController. Moreover invalid urls are 'forwarded' not redirected to welcome file.
Map error page to home page- This is cheating with yourself. I don't want to hide errors.
Use two servlets. One with "/*" mapping, which redirects everything to 'mysite.com'. Second mapped to ""(empty) that actually serves request. - Some mysterious issues here(yet to figure out)
I think, everyone wants to achieve same functionality for their home screen and there are many questions at stackoverflow with similar problems.
Is there any standard solution which solves problem for once and for all.
Edit:- There were only 7 views in more than 30 mins. Removed GAE tag, to attract more views.
Simply put a web server before your app server and you can map any URL to any application/page. Also don't publish an app server directly.
Are you using Tomcat I presume, so you probably deployed ROOT application, right? (you should go with the web server anyway)

Categories

Resources