Why does the url localhost:8080////ProjectCtxt/mvc/template works in the following Spring MVC project?
-
Following is my spring MVC web application. 1) I don't know why my application with four forward slashes after port number works. How to fix this. dispatcher-servlet.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="Index of /schema/beans" xmlns:xsi="Page on w3.org" xmlns:mvc="Index of /schema/mvc" xmlns:tx="Index of /schema/tx" xmlns:context="Index of /schema/context" xmlns:p="Page on springframework.org" xsi:schemaLocation="Index of /schema/mvc Page on springframework.org Index of /schema/tx Page on springframework.org Index of /schema/beans Page on springframework.org Index of /schema/context Page on springframework.org"> <context:component-scan base-package="com.ProjectCtxt.www.controller"/> <mvc:annotation-driven /> <mvc:resources mapping="/resources/**" location="/resources/" /> <!-- <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" /> --> <bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"> <property name="definitions"> <list> <value>/WEB-INF/tiles.xml</value> </list> </property> </bean> <bean class="org.springframework.web.servlet.view.tiles2.TilesViewResolver"/> <bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass"> <value> org.springframework.web.servlet.view.tiles2.TilesView </value> </property> </bean> </beans> appContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="Index of /schema/beans" xmlns:xsi="Page on w3.org" xmlns:mvc="Index of /schema/mvc" xmlns:tx="Index of /schema/tx" xmlns:context="Index of /schema/context" xmlns:p="Page on springframework.org" xsi:schemaLocation="Index of /schema/mvc Page on springframework.org Index of /schema/tx Page on springframework.org Index of /schema/beans Page on springframework.org Index of /schema/context Page on springframework.org"> <!-- MVC context is separate from the app context usually. --> <!-- component scan is not recursive --> <context:component-scan base-package="com.ProjectCtxt.www.service" /> <!-- Factory bean that creates the Mongo instance --> <bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean"> <property name="host" value="localhost" /> </bean> <!-- MongoTemplate for connecting and quering the documents in the database --> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongo" ref="mongo" /> <constructor-arg name="databaseName" value="tableName" /> </bean> <!-- Use this post processor to translate any MongoExceptions thrown in @Repository annotated classes --> <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /> </beans> web.xml <web-app version="2.2" id="WebApp_ID"> <!-- <display-name>Archetype Created Web Application</display-name> --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/appContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet </servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/dispatcher-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/mvc/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app> ProjectController.java package com.ProjectCtxt.www.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import com.ProjectCtxt.www.service.ProjectService; @Controller("resultController") public class ResultController { private final ProjectService projectService; @Autowired public ProjectController(ProjectService projectService) { this.projectService = projectService; } @RequestMapping(value ="/template", method = RequestMethod.GET) public String getPersonList(ModelMap model) { return "header"; } @RequestMapping(value ="/search", method = RequestMethod.GET) public String getStudentResult(String rNo, ModelMap model){ return "numberResult"; } } 2) Also when I am working on my project in my local machine I always use loclahost:8080/ProjectCtxt/mvc/template but when I deploy in production I want it to be http://mywebsite.com . How can I do this? 2a) When I tried `http://www.google.com////calendar/render%60, it works. But when I type `http://www.google.com/calendar////render%60 it doesn't work. 3) If I use localhost:8080/ProjectCtxt/mvc/template I go to homepage. When I click search button in my jsp, my url becomes `http://localhost:8080/search?regNo%60. But if I manually change `localhost:8080/search?regNo=` to `localhost:8080/ProjectCtxt/mvc/search?regNo=` it works? Why is this? How can I fix the url to automatically be `localhost:8080/ProjectCtxt/mvc/search?regno=` rather than typing "ProjectCtxt/mvc/search?regNo=" manually tiles.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN" "Page on apache.org"> <tiles-definitions> <definition name="template" template="/WEB-INF/jsp/template.jsp"> <put-attribute name="title" value="Lets see"/> <put-attribute name="header" value="/WEB-INF/jsp/header.jsp" /> <put-attribute name="body" value="/WEB-INF/jsp/ads.jsp "/> <put-attribute name="center" value="/WEB-INF/jsp/ads.jsp" /> <put-attribute name="footer" value="/WEB-INF/jsp/footer.jsp" /> </definition> <definition name="header" extends="template"> <put-attribute name="title" value="" /> <put-attribute name="body" value="/WEB-INF/jsp/ads.jsp" /> </definition> <!-- <definition name="bottom" extends="new.template"> <put-attribute name="bottom" value="/mvc/jsp/ads.jsp" /> <put-attribute name="bottom" value="/WEB-INF/jsp/ads.jsp" /> </definition> --> </tiles-definitions> header.jsp <%-- <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="Page on apache.org" prefix="tiles"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "Page on w3.org"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <center> <h1>Header</h1></center> <tiles:insertAttribute name="body" /> </body> </html> --%> <form action="/search" method="GET" > <div style="text-align: center;"> <input type="text" id="regNo" name="regNo" size="30" maxLength="50" placeholder="ABCD"></input> or <input id="collName" type="text" size="30" maxLength="50" placeholder="EFGH"></input> </div> <div style="text-align: center;"> <input type="submit" value="search"><br/> </div> </form>
-
Answer:
Ok, 1) Multiple path-separators don't (mostly) make any difference until you are using some kind of URL-rewriting. Read http://stackoverflow.com/a/10161264/2555504 This is why localhost:8080////ProjectCtxt/mvc/template works. 2)As much as I understand, you want to host your project with a custom domain name and want to have files in "ProjectCtxt/mvc/template" to be your homepage. If that's the case, I will suggest you to host the web-app on https://developers.google.com/appengine/ and then get a custom domain https://cloud.google.com/appengine/docs/domain. 2)a)As you must have read in the first point, multiple separators don't make any effect but only mostly, not always. They may effect in case of different ways of URL-rewriting or how different browsers and servers render it. This is why one works and the other doesn't. 3)In your "header.jsp" ,change form action value from "/search" to "search" and it should be fine, because backslash(/) refers to root path of the project.
Saurabh Goyal at Quora Visit the source
Related Q & A:
- How can I access my localhost from my Android device?Best solution by Stack Overflow
- Why MVC is not suitable for Windows application?Best solution by Stack Overflow
- Why does my messenger works backwards?Best solution by Yahoo! Answers
- Which of the following atom is the most paramagnetic and why?Best solution by Yahoo! Answers
- Why does my psp does not turn on and the battery works?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.