I have created Dynamic web project in eclipse, when i run the project on browser the URL is http://localhost:8080/magicmonitor/panels.jsp it's work fine, but my requirement is i want to change the URL dynamically, in the above URL magicmonitor is my project name, it's tomcat behavior it's take the default url is http://localhost:8080/magicmonitor (Host:Port/Projectname) i want to execute same on http://localhost:8080/dev/magicmonitor/panels.jsp how to do that?
1
votes
1 Answers
1
votes
To change the URL you need to do three things:
- Change the context root of your web project from magicmonitor to dev
- Add the mapping dev/magicmonitor/panels.jsp for your JSP.
- Clean Tomcat to remove the existing application settings and pick up the application configuration changes you have made.
Step 1 of 3: Change the context root:
- Select your project node in Project Explorer, right click and select Properties.
- Select Web Project Settings from the list of entries on the left.
- In the Context root field change the value from magicmonitor to dev, then click Apply And Close.
Step 2 of 3: Add a mapping for the JSP:
Edit the project's WebContent/WEB-INF/web.xml to add a mapping for your JSP between the submitted URL and the JSP file:
<servlet> <servlet-name>PanelsJsp</servlet-name> <jsp-file>/panels.jsp</jsp-file> </servlet> <servlet-mapping> <servlet-name>PanelsJsp</servlet-name> <url-pattern>/magicmonitor/panels.jsp</url-pattern> </servlet-mapping>
That <url-pattern> will be appended to the context root (which is now dev) when matching the URL you submit. If the URL submitted from the browser matches the <url-pattern> the <jsp-file> will be called.
Step 3: To republish:
- In the Servers view: stop Tomcat, select the Tomcat server, right-click and select Clean... from the popup menu.
- You will be prompted "Clean will discard ... Are you sure you want to clean all published resources?".
- Click OK, then start Tomcat.
You should now be able to access your JSP page using the URL http://localhost:8080/dev/magicmonitor/panels.jsp
http://localhost:8080/
is possible, I'm not sure if it possible to achieve what you've asked for! – N00b Pr0grammer