Impossible to display static images saved on tomcat server in a jsp after trying all context docBase configurations - image

Im unable to display an image uploaded by a user on my local server (D:\fichiers)in a JSP,
using pure Jee (no spring), Tomcat 9, intelli-j idea.
I've tried everything i could find :
I tried to add :
<Context docBase="D:\fichiers" path="/images"/>
in context.xml in meta-inf, in server.xml in Tomcat installation conf folder, in server.xml in Tomcat/conf of the app, in catalina/localhost/root.xml, in catalina/localhost/context.xml.
But i still get an error 404, images not found.
Here is the server.xml file :
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Context docBase="D:\\fichiers" path="/images"/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b"/>
</Host>
and the jsp call :
<c:set var="chemin">/images/</c:set>
<c:forEach items="${spot.photos}" var="photo">
<img src="${chemin}${photo.nom}"/>
</c:forEach>
The only time it worked is when i checked on tomcat configuration
Deploy applications configured in Tomcat instance
But i had to remove it, cause Catalina was starting springframework on its own, and nothing worked properly after that.

Ok i found the answer, and though it's stupidly simple, i couldn't find a place where it was said.
In Tomcat configuration tab in Intelli-j :
Deployment Tab -> Add external Source -> Select the local Drive -> Put URL desired in Application Context, and that's it !

Related

Spring boot war package in tomcat webapps

My spring boot application.yml:
server:
port: 9999
servlet:
context-path: /test
and i put the war package in tomcat webapps
and my server.xml
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="/" docBase="test" debug="0" privileged="true" reloadable="true"/>
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
when i access the localhost:9999/test/index ,it does not work
What is the correct configuration?
as far as I can tell you have to change the port of the tomcat if you want to run it as localhost:9999/test/index 9999 should be the tomcat's port on which the webapp will respond

how to log requested path in access log?

We are using Jboos Eap 7.1 in our organization with access log enabled with the following pattern:
<access-log pattern="%h %l %u %t %r %s %b %{Referer}i %{User-Agent}i %{COOKIE}i %{SET-COOKIE}o %S %I %T"/>
Each 5 minutes server log says:
[org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] (default task-49) Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation]
But in access log we see:
GET /general-error.html HTTP/1.1 404
Which is a fallback page for errors, so we don't know which url or spring controller is being requested, how can I see actual requested path like nginx does?
You can configure Request logging / RequestDumping handler using following commands.
Create a new Expression Filter with the RequestDumping Handler
/subsystem=undertow/configuration=filter/expression-filter=requestDumperExpression:add(expression="dump-request")
Enable the Expression Filter in the Undertow Web Server
/subsystem=undertow/server=default-server/host=default-host/filter-ref=requestDumperExpression:add
Above commands will add the following configuration in domain.xml/standalone.xml in undertow subsystem
<server name="default-server">
<http-listener name="default" socket-binding="http" redirect-socket="https"/>
<host name="default-host" alias="localhost">
...
<filter-ref name="requestDumperExpression"/>
</host>
</server>
...
<filters>
...
<expression-filter name="requestDumperExpression" expression="dump-request"/>
</filters>
The output will be logged in server.log file.
Refer following url for more detail :
https://access.redhat.com/solutions/2429371

how can i check if vhost is enabled on tomcat7

I am trying to add a vhost to my already running tomcat7 server.
I already have my default application running on tomcat successfully.
<Host name="mydefault.com" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Host name="myNewHostDomain.com"
appBase="wings_microx_cash_reports"
unpackWars="true" autoDeploy="true">
i have added the domain as well on dns (godaddy) and ping is running fine.
But when i check the logs in /usr/share/tomcat7/logs, i do not see anyinfo with respect to my new vhost
Also, when i send in a http request to my new host, i see the default host app is running
<Engine name="Catalina" defaultHost="mydefault.com">
Any pointers how i can check/rectify this?
sorry for false alarm
i had not closed the tag pproperly.

Accessing Tomcat manager throws 404

I am using Tomcat 7.0.65.
Here is my tomcat-users.xml:
<role rolename="manager"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-status"/>
<user username="admin" password="tomcat" roles="manager,manager-gui,manager-script,manager-status"/>
Here is the server realm snippet in server.xml
<Realm className="org.apache.catalina.realm.MemoryRealm" />
I can access the below urls : [It asks for the credentials for the first time]
http://localhost:8080/manager/status
http://localhost:8080/manager/status/all
But accessing any of the urls :
http://localhost:8080/manager/text/sessions?path=/examples
http://localhost:8080/manager/text/serverinfo
fails with "404 Not found". Below is the displayed error message:
The page you tried to access (/manager/text/sessions) does not exist.
The Manager application has been re-structured for Tomcat 7 onwards and some of URLs have changed. All URLs used to access the Manager application should now start with one of the following options:
/manager/html for the HTML GUI
/manager/text for the text interface
/manager/jmxproxy for the JMX proxy
/manager/status for the status pages
Note that the URL for the text interface has changed from "/manager" to "/manager/text".
You probably need to adjust the URL you are using to access the Manager application. However, there is always a chance you have found a bug in the Manager application. If you are sure you have found a bug, and that the bug has not already been reported, please report it to the Apache Tomcat team.
Note that I am accessing the url as /manager/text . Even curl fails with the same error.
Am I missing any configuration?
After much debugging, I found the real cause was the ManagerServlet was failing to get instantiated with the below security exception:
java.lang.SecurityException: Restricted (ContainerServlet) class org.apache.catalina.manager.ManagerServlet
The way to fix is to set "privileged=true" in the "Context" section in TOMCAT_INSTALL_DIR/conf/context.xml
<!-- The contents of this file will be loaded for each web application -->
<Context privileged="true">
<!-- Default set of monitored resources. If one of these changes, the -->
<!-- web application will be reloaded.
Provide the roles below in the conf/tomcat-users.xml file.
<user username="test" password="test" roles="admin-gui,manager-gui"/>

URL redirection from Apache to Tomcat using mod_jk

My apache document root is /srv/www/htdocs/ and my url is https://internal.net/
My requirement is to open a URL https://internal.net/jenkins-project/ which should have document root as /usr/share/tomcat7/webapps/jenkins-project/ rather than looking into /srv/www/htdocs/jenkins-project/
I tried using mod_jk and have configured a worker property with name worker1 and am using it in httpd.conf as mentioned below
JkMount /jenkins-project/* worker1
But still throwing an error
File does not exist: /srv/www/htdocs/jenkins-project/
I have used below code in tomcat's server.xml and restarted Tomcat. Its working fine now.
<Context path="/jenkins-project" docBase="jenkins-project" debug="0" reloadable="true">
<Logger className="org.apache.catalina.logger.FileLogger" prefix="jenkins-project" suffix=".log" timestamp="false"/>
</Context>

Resources