I have deployed Myapplication.war in tomcat webapps directory.
now i have, index.jsp in $CATALINAHOME/webapps/Myapplication and process.class in $CATALINAHOME/webapps/Myapplication/WEB-INF/classes.
When index.jsp post some variables to process, http://x.x.x.x:8080/Myapplication/process
Im getting below err,
type Status report
message /Myapplication/process
description The requested resource is not available..
if i convert the process file from java class to jsp, im able to post from index.jsp to process.jsp.
How can i achieve this? any other settings i need to do here?
Thanks in advance
You'll have to declare your servlet in web.xml otherwise Tomcat won't know which class to associate with which path:
<servlet>
<servlet-name>processServlet</servlet-name>
<servlet-class>process</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>processServlet</servlet-name>
<url-pattern>/process</url-pattern>
</servlet-mapping>
See also the tomcat sample deployment descriptor
A couple of minor niggles:
As per Java class naming, classes should start with an uppercase character, so it would be Process and Process.java.
Usually it makes more sense to put java classes into a package.
Related
I have the following problem:
In my web.xml I define how to serve pictures like so:
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
<url-pattern>*.png</url-pattern>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
On Tomcat this works fine but on IBM Websphere 8.5.5.9 I get the following error:
"SRVE0303E: Servlet name for the servlet mapping *.css could not be found."
On another site I already found a solution for this issue (https://www.ibm.com/developerworks/community/forums/html/topic?id=5f4420ba-0754-43fe-8c87-91acc588d9fc) so I also created the ibm-web-ext.xml exactly the same as in their solution but the error still persists.
Does anyone know what I could do differently?
I found the answer to my problem, thanks to #MigratedPigeon because he got me thinking about the class of my default servlet.
A tomcat server has a default servlet, the class for tomcats default servlet is
org.apache.catalina.servlets.DefaultServlet
Websphere on the other hand does not have a default servlet, thats why I get the error "Servlet Name could not be found".
As in the answer I linked in the original question, static file serving can be activated by websphere by using the web-ext.xml file but that still did not solve the issue of my web.xml file having a "default" servlet.
In our application we use spring, so in the end I replaced the default servlet in web.xml with springs dispatcher servlet and now my web.xml file is valid for both, tomcat and websphere.
you should also mention this in your web.xml
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>your servlet class</servlet-class>
</servlet>
Servlet mapping is done based on the value mentioned in the "" tags and respective servlet will be called.
I have configured my tomcat6 web.xml to show my custom error page by adding these lines, described here
<error-page>
<error-code>500</error-code>
<location>/web_server_error.html</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/web_server_error.html</location>
</error-page>
Also I came to know for each application deployed I need to put the same configuration as I did for ROOT, which is fine.
My issue is I have a simple folder webapps/docs. If I try to access any file existing in this folder say /docs/mypage.html, I can access it perfectly but if the file or directory doesn't exist in the folder like docs/faq/ I need the same error page but tomcat is showing its 404 error page.
Actually I need it because my client mention this in a vulnerability list, i.e. in this scenario the attacker can get aware of the file structure so we need to show one page on all errors.
I need to know as it is a simple folder instead of any application how to handle this issue or is it simple impossible?
Any help is highly appreciated.
This is not possible in Tomcat 6. Servlet 3.0 specifies global error pages but Tomcat 6 implements Servlet 2.5.
But it's possible to "workaround" by writing a ErrorReportValve class and register it. But beware: This is Tomcat specific!
The folder is not a web application.so your configure does not work!
We are deeper into our project, and have set up a basic web application with eclipse. Whenever we attempt to run the server, we get a 404 error like the following
From my research, I have found I need some sort of web.xml file. Where should put this file what should be in it. How do I make it
Your problem is your trying to access a resource within the WEB-INF folder, that is not allowed and that is the reason you have this error, you must put the jsp under the WebContent folder or any folder under the WebContent folder.
The WEB-INF\classes contains the .class files for your Java classes and it's not a good place to put any resource.
Since the 3.0 specification for servlets the web deployment descriptor (web.xml) is optional.
I hope this could help you to fix your problem
Putting JSPs under WEB-INF makes them inaccessible unless you map them in WEB.XML The purpose of WEB-INF is to hide things because users cannot download or access anything under WEB-INF. You only put JSPs under WEB-INF if you don't want the user to be able to go there by its real name (i.e. http://localhost/app/whatever.jsp) but want to map it to some specific url (i.e. http://localhost/app/somename/)
Mapping a JSP that is under WEB-INF to a URL cane be done with this in the WEB.XML
<servlet>
<servlet-name>somename</servlet-name>
<jsp-file>/WEB-INF/whatever.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>somename</servlet-name>
<url-pattern>/somename/*</url-pattern>
</servlet-mapping>
Of course, if you need to map another URL to the JSP but don't feel the need to disallow the user from going there by its .jsp filename, you can use a URL Rewriting filter for that. In that case, there is no point in putting it under WEB-INF.
I have a WAR file with a web application that has been deployed to a weblogic stream.
The JSP part works fine, but it can't find the servlets. Possible due to the lack of mapping in my web.xml file.
I was working fine on Tomcat 6, but can't seem to find using weblogic.
I used annotation #WebServlet("/actionOne") but this doens't seem to work.
I am a little confused about how to map these correctly via the web.xml file.
the servlets are .java files and located at WEB-INF/classes/com/foo/bar/
So far I have added the following the web.xml file but the servlet-mapping section has me confused.
<servlet>
<servlet-name>actionOne</servlet-name>
<servlet-class>com.foo.bar.actionOne</servlet-class>
</servlet>
<servlet>
<servlet-name>actionTwo</servlet-name>
<servlet-class>com.foo.bar</servlet-class>
</servlet>
Hopefully the above is correct, the next section I'm not sure how to use and would appreciate some help.
<servlet-mapping>
<servlet-name>actionOne</servlet-name>
<url-pattern>/actionOne</url-pattern>
</servlet-mapping>
The servlets are being called from the jsp via a Form action="actionOne"
My mapping was correct, it seems the issue was related to a different version of servlet.api in the weblogic modules folder. 2.5 instead of 3.0. This resolved the issue.
So I have files such as index.jsp and download.jsp in my web application widget.war and am using Tomcat 7. I would like these files to be accessible from the internet as html files i.e
http:/www.mycompany.com/widget/index.html
http:/www.mycompany.com/widget/download.html
Questions:
How do I do this, I know it can be done as I did it about 5 years ago but cannot remember how.
Is it a good idea, it seems like a good idea as users are familar with html but jsps, and returning as jsps shows an implementation detail, but does it matter ?
You can map *.html through your application's web.xml to the jsp servlet defined in tomcat_path/conf/web.xml.
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
However, extensions in general are an implementation detail, so it makes no big difference to your users if the URL ends with .html or .jsp. Most won't probably care anyway.