我想實現URL編碼就像我的春天web應用程序http://www.host.abc/action?view=jobs,但不能把工作通過我的策略,這是做無法將URL重定向春季
@Controller
public class HomeController {
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
/**
* Simply selects the home view to render by returning its name.
*/
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
logger.info("Welcome home! The client locale is {}.", locale);
return "home";
}
@RequestMapping(value = "/home/action?view=jobs", method = RequestMethod.GET)
public String showJobs(Model model) {
//some stuff goes here
return ("/home/action?view=jobs");
}
}
回到Home.jsp是
<c:if test="${param.view == 'jobs' }">
<!-- List of Jobs -->
</c:if>
這給我警告
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/jobsnetwork/home/action] in DispatcherServlet with name 'springDispatcher'
,最後我說馬平到WebApplicationInitializer CLAS S作爲
public class AppInit implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext context) {
XmlWebApplicationContext rootContext =
new XmlWebApplicationContext();
rootContext.setConfigLocation("/WEB-INF/spring/root-context.xml");
context.addListener(new ContextLoaderListener(rootContext));
// Create the dispatcher servlet's Spring application context
XmlWebApplicationContext servletContext =
new XmlWebApplicationContext();
servletContext.setConfigLocation("/WEB-INF/spring/appServlet/servlet-context.xml");
// add the dispatcher servlet and map it to/
ServletRegistration.Dynamic dispatcher =
context.addServlet("springDispatcher", new DispatcherServlet(servletContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
dispatcher.addMapping("/home/action");// added mapping here
}
}
上面的東西是不工作
仍然相同的警告和HTTP狀態404 - –
I edi特德。應該是@RequestMapping(value =「/ home/action」,',不是'@RequestMapping(value =「/ home/action?view = jobs」,'。 – acdcjunior
Man!仍然是相同的警告和HTTP狀態404 –