Add a servlet will disable all servlet - java

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.

Related

The webpage cannot be found - HTTP 404 JSP page

Experts,
My dynamic web project having 3 JSP page and 3 servlets .. and everthing was working fine till date.
when i executed the same project today, it was showing this below message.
The webpage cannot be found - HTTP 404
I deleted the whole project after trying multiple checks... now in web.xml if i remove the servlets section, its displaying the jsp content. but if i add the servlet back its throwing same page cannot be found :(
no error in project and i dont see any logs in eclipse... can someone please tel me why this is happening?
Appreciate your input. Thanks
Below are a few general suggestions on debugging web apps:
3 and 4 would be the first checks for 404.
Try to start the web app in the debug mode, and place the break point in the servlet method: any hit? (or just put a System.out.println in the Servlet);
Check the structure of the dynamic web project in Eclipse: are the compiled java classes of the servlets in there?
Check the context path (url) of the dynamic web project in eclipse project config: not accidentally changed?
Check the log files of the tomcat (access logs and catalina logs) your dynamic web project is associated with.

Forwarding a request from servlet to .jsp fails when deployed on remote server

I have been stuck with this problem for two days now and I cant find a solution.
I have this project structure as above:
I want to forward a request from Survey(it is a Servlet) to survey.jsp.
Now when I deploy this from IntelliJ on localhost the forward is made with success. Now i take the .war and use the Tomcat Apache manager to deploy it to a dedicated Server.
When i call dedicatedserverip:8080 the index.jsp loads properly as in localhost:8080. But when it comes to forward there are two cases:
When the name of .war file is different from survey.war when the forward happens I get error 404 . (In this case I think that the request is forwarded to dedicatedserverip:8080)
When the name of .war file is survey.war when forward happens it happens to load again index.jsp page. (in this case I think the request is forwarded to dedicatedserverip:8080/survey)
Below is the code I use to forward the request:
req.getRequestDispatcher("/survey.jsp").forward(req, resp);
Now my question is: Is there something done wrong? Or is there something that I must understand that I haven't? How can I fix it and get the needed result as in localhost?
Have you tried forwarding relative instead of absolute?
req.getRequestDispatcher("survey.jsp").forward(req, resp);
Then additionally it should be no problem if you change the name of your war file and with it the ServletContext of the application any more.
Finally, I solved the problem. It had nothing to do with the forward, the problem was in the submit form action. Action was action="/survey". I replaced with ${pageContext.request.contextPath}/survey . And it solved the problem. This explains why the index page was called when .war name was survey.warand error page when it was different.
Thank you for your support.

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.

Still have Eclipse EE 404 on Mac after following advice on this issue

First of all, I am aware that there are other questions regarding Tomcat, Eclipse, and the infamous 404 error. However, none of them manages to resolve the issue. I have spent well over 24 hours on this issue.
To save time, when I configured everything (including Tomcat, and creating a server in Eclipse), I:
• Changed the server location from "workspace metadata" to its correct location by using the "Switch Location" button located in the server's Properties window.
• I chose the "Use Tomcat Installation" option in Server Locations, and saved the choice I made.
In both cases, I restarted the server. If you're curious as to what app I'm currently working on, it's a simple Hello World app, found at: http://theopentutorials.com/examples/java-ee/servlet/how-to-create-a-servlet-with-eclipse-and-tomcat/
• I have included the Java file in the "welcome file" list inside web.xml.
Lastly, out of curiosity, why does the Eclipse browser only go to the project directory, and not the servlet itself? (If I add on the servlet name, then "Hello World" appears).
• Yes, if I enter "http://localhost:8080", the default Tomcat page appears, so no issues there.
Can anyone clue me in, as to why I am still getting 404s after all this, and following advice that has been marked as "Accepted" here at SO, such as the following:
HTTP Status 404 - The requested resource (/) is not available
Thanks in advance for any help, it is greatly appreciated.
The error 404 may occur because of large amount of different reasons. In order to resolve that, you should check your tomcat log file out first. It contains by the path:
%PATH_TO_WORKSPACE%\.metadata\.plugins\org.eclipse.wst.server.core\tmp%SERVER_NUMBER%\
logs
Usually it contains some stacktraces which discribes the problem. If not, then you should check your deployed application out there:
%PATH_TO_WORKSPACE%\.metadata\.plugins\org.eclipse.wst.server.core\
tmp%SERVER_NUMBER%\___YOUR_APP____
It might happen that your application was not deployed correctly by eclipse plugin (happens very often) and you should try this:
Project --> clean
'Right click on your server' --> clean
Or just remove your webapp from the directory I mentioned erlier and redeploy it from scratch.
There is something basic you need to understand regarding using tomcat(or application server for that matter). There is a slight difference between using from Eclipse and using from outside
Using From within Eclipse
What happens here is that Eclipse (by default) uses a copy of your tomcat installation and places it in its metadata workplace. This secondary tomcat is used by Eclipse for all deployments, re-deployments and all. Keep in mind that this is not your original copy of tomcat installation.
The difference in this tomcat installation is that is actually a minimal server, meaning that although it has all the deployment capabilities, it does not have some of the extra features that come with the tomcat installation and one main feature is the tomcat's homepage (the only reason why people out there get the infamous 404 resource not found when they try to run-on-server their application).
Workaround
Although not an issue (nor a bug from the Apache's end), you can still view your application by changing the URL to your application's url, homepage or no homepage ! All you have to do is change the url from http://localhost:8080 to http://localhost:8080/yourApplicationName and voila , the default page of your application will be shown that you mentioned in the welcome-page-list. Keep note that if you didn't specify a default page in your web.xml, you will again wind up with, yet again, the dreaded 404 resource not found page. The reason is that Tomcat has found your application, but it doesn't know what to do at the root context of your application. You can either map your servlet to the root of the application (that way it will always run at http://localhost:8080/yourApplicationName) or you can change the URL to the url-pattern that you mapped with the servlet in the web.xml, it must be something like http://localhost:8080/myApplicationName/myServletMappingPattern

How to know which is the JSP webpage that is showing my servlet

I have a project that I can see the JSP's... However Jboss shows me the servlets so in the address bar all i can see is:
"appservleer?=AppDev"
This is an example not the actual address...but with that info only how can I know which JSP is being displayed at that moment by JBoss.
or am I understanding this Jboss, servlet, JSP incorrectly?
Some guidance would be appreciated.
Thanks.
You cannot know which jsp is being displayed unless the developer decided to give hints about it.
A jsp is just a view technology that the servlet uses to render a response. That is, typically, the jsp will be parsed and html will be generated. However, the developer of the servlet may decide to write to the response himself. So nothing can really tell you if what you got came from a jsp or from another source, even if you had a url like www.mydomain.com/page.jsp. Nothing guarantees the response you are seeing in your browser was generated from a jsp.
The only way to know for sure which JSP is used for rendering is to look at the source code of the servlet that is mapped under (in your example) "appservleer".
Look in web.xml which servlet is mapped with this path, and open the source code of this servlet. Then figure out the execution path, starting with the doGet(...) or the doPost(...) method, and see to which JSP it is forwarded in the end...
Good luck.
You should always start with the web.xml file which will eventually lead you to the actual jsp file that is displayed. Start with the servlet mapping and check which servlet is invoked for the url. Then dig into the servlet to find out which jsp it is redirected to. If you are using any application framework then look for the implementation to findout the mapping. For e.g. in spring the spring configuration files or the controller classes tells you where the calls are redirected to.

Categories

Resources