I deployed application in tomcat under webapps/testing1 folder.
http://localhost:8080/testing1/index.html
This html page has anchor tag with href as "/login"
When I click on anchor, it takes to localhost:8080/login instead of localhost:8080/testing1/login
I did not do any change in tomcat conf xmls. How can I make all paths starts with slash would goto application context?
Suggestions would be appreciated.
By declaring a link href="/login" you make that an absolute link on your host. If you want login inside your app you'd have to prepend the context path (request.getContextPath ()) or use relative links ( href="login" )
If you deployed context successfully in Tomcat and it is Start up successfully. Then the Application access directly the web.xml from the WEB-INF folder.
It access the servlet using the <url-pattern> and <servlet-class> to identify the servlet.
If you are worrying about accessing HTML files from the servlet you can access them directly from the context path.
i.e
if file present at CONTEXT/html/file1.html you can access it as html/file1.html
if file present at CONTEXT/file2.html you can access it as file2.html
You have to specify the . prefix to the href value.
<a href="./login"> so that the URL will be localhost:8080/testing1/login
Related
My angular application is bundled and deployed together with a java application. Angular AOT build is placed in the folder WebContent/app.
While taking the AOT build,
If I specify --base-href /app, I'm getting 404 after loading the index.html. In that case, I have to add --deploy-url /app/ during my build, for the application to be working properly.
But If I specify --base-href /app/ then scripts, styles, and other resources are served correctly. And there's no need to specify --deploy-url
What I could observe is that If I don't append "/" to base-href, the server request made is using the context-root - http://localhost:9080/application-name/styles.***.css and when I append the "/", server context-root is appended with app - http://localhost:9080/application-name/app/styles.***.css
Why is adding "/" at the end of base-href make all this difference?
Could someone explain this behavior as I'm not able to find anything on docs?
Thanks in Advance.
After some digging, I found the answer. It is not related to Angular at all.
Tha <base> tag is part of HTML Specification: Link
As MDN Doc says,
The HTML < base> element specifies the base URL to use for all relative URLs in a document. There can be only one < base> element in a document.
It is used to specify the base of relative URLs.
So coming into my problem
When <base href="/app"> is used, the browser treats the href as a file rather than a directory. So the base URL will not be prepended to relative URLs.
When <base href="/app/"> is used, the browser treats it as a directory and all relative URLs will be prepended by base URL.
More can be found out here and here
I am using Apache-Tomcat-7 and I placed a jsp page( myjsp.jsp ) in
...\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\desktop\
I have started the tomcat and trying the following URL to open the jsp page
http://localhost:8089/desktop/myjsp.jsp
But it is giving 404. I donot want it to open through other means. Can any body tell me that what I am doing wrong?
P.S. localhost:8089 works fine for other applications and tomcate is configured to this port-8089.
EDIT
When I placed the myjsp.jsp in ROOT folder under
...\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ROOT\
and try
http://localhost:8089/myjsp.jsp
Now it works. So what is the reason that in the desktop folder the jsp was NOT found
OR
how can I access myjsp.jsp if it is placed within desktop folder?
Well one way is the way you have already done (by deploying it at the root context of the tomcat server). Although it would seem to work fine, I won't recommend doing that. Changing root context of tomcat to some other application/pages is for other purpose.
The best way to do is to create a small project (you need a dynamic web project with a proper deployment descriptor --> eclipse will do all this job by just a button click), then deploy this project to your tomcat server.
So lets say if you create your project as MyProjectOne, then just place your JSP page (lets call it test.jsp) under WebContent or src/main/webapp folder and you will be able to view your page as http://localhost:8089/MyProjectOne/test.jsp
One of our project we deployed in tomcat 5.5. our code is not an war file. deployed as a jar.
and we did not deploy directly under webapps . we created new folder and placed everything over there.
and we configured that path in server.xml under context tag
<code>
< Context path="/ABC" docBase="/app/apache-tomcat-5.5.26/webapps/ABC/"
debug="1" reloadable="true" crossContext="true">
< /Context>
</code>
The problem is.
we were able to land on home page but the images are not load and none of the links are not working
Home page link ; //ip:port/ABC/home.jsp
when we click any of the links then the context path is getting removed like the below
one of the link : //ip:port/firstlink.jsp
please help me where we have to config the context path
Thanks in advance
Your link <a href="/home.jsp"> is absolute to your domain, you need to include the context in the URL. To obtain the current context use request.getContextPath
getContextPath
String getContextPath()
Returns the portion of the request URI that indicates the context of
the request. The context path always comes first in a request URI.
The path starts with a "/" character but does not end with a "/"
character. For servlets in the default (root) context, this method
returns "".
...
Returns:
a String specifying the portion of the request URI that indicates the context of the request
HttpServletRequest#getContextPath()
You can retrieve this value in JSP with ${pageContext.request.contextPath}. Your link should be:
Home
I am working on web application.I invoke on my jsp request.getContextPath(), but strangely I got address /streetshop.
Then I am appending some path as request.getContextPath() + "abc" and create folder.
Then its creating folder in D:// instead of my webapplication folder.
Please, tell me, I want to upload an image in put it in my web-application root/images/images.gif.
You mix things up here. HttpServletRequest.getContextPath() returns your web application root path. In your example this is /streetshop, so your URL may look similar to www.myapp.com/streetshop. If you want to access the internal file system path, you must obtain it from the ServletContext using request.getServletContext().getRealPath("/"). This should return the location of your WAR files' WebContent folder.
Keep in mind that if you modify contents of this path during runtime, you're going to loose everything when redeploying your application.
I am trying to make servlet.
I have installed tomcat6 on ubuntu with admin examples and docs. I am able to run the examples provided. But when i try to make my own servlet it doesnt work.
I did following steps
Under the ROOT i create folder with
-ROOT
----myapp
------WEB-INF
---------classes
I made two files one is index.html which have a button and action on form to call the servlet. Second is .java file. I compiled the .java file and .class is done. So now tree look like
-ROOT
----myapp
------index.html
------WEB-INF
---------classes
-----------TestServ.java
-----------TestServ.class
Now i open this in browser using http://localhost:8080/myapp
It shows up with index.html page with button. But when i click on the button it says
Error 404:
http://localhost:8080/myapp/TestServ not found !!
I dont know where m going wrong. I have set the CATALINA_HOME too. But still this problem continue.
You need to create a web.xml in the WEB-INF directory, and define the servlet mapping in web.xml, so that the myapp/TestServ URL is forwarded to the TestServ servlet class.
Here is a page describing web.xml, and has the example and elements you need to set up. For your class, these elements will probably look something like this:
<servlet>
<servlet-name>testServ</servlet-name>
<servlet-class>TestServ</servlet-class>
</servlet>
<servlet-mapping>
<!-- For any URL starting with /content/, the rewriter servlet will be called -->
<servlet-name>testServ</servlet-name>
<url-pattern>/TestServ</url-pattern>
</servlet-mapping>
You shouldn't be deploying any of your code under ROOT.
You shouldn't have any Java class in the default package. Try putting your TestServ.java in a package.
Your deployment should NOT include any .java files.
You've got to register your servlet properly in web.xml. Include a mapping to a particular URL.
Your best best is to create a WAR file named myapp.war, which includes WEB-INF/classes and WEB-INF/lib and a web.xml for your situation. Put that in the Tomcat /webapps and start the container. If you've registered your servlet properly you should be able to access it via http://localhost:8080/myapp/TestServ.
I'd read the deployment docs carefully.