Tag: url routing

如何使用注释在SpringMVC中创建默认方法?

我无法找到解决方案,这让我发疯了。 我有@Controller映射,使用@RequestMapping响应多个方法。 当没有指定更具体的内容时,我想将其中一个方法标记为默认方法。 例如: @Controller @RequestMapping(“/user/*”) public class UserController { @RequestMapping(“login”) public String login( MapModel model ) {} @RequestMapping(“logout”) public String logout( MapModel model ) {} @RequestMapping(“authenticate”) public String authenticate( MapModel model ) {} } 所以/ user / login – > login方法,/ user / logout – > logout等。我想这样做,如果有人去/ user,那么它会路由到这些方法之一。 但是,我没有在@RequestMapping上看到任何允许我将这些方法之一指定为默认处理程序的内容。 我也没有看到任何其他注释可能在类上使用这样做。 我开始怀疑它不存在。 我正在使用Spring 2.5.6。 这是在3.0.0中解决的吗? […]

如何在Struts 2中使用没有后缀的URL(例如.action)?

这就是我需要的东西,我不仅需要使用我的.war来提供java,还需要一些javascript文件。 所以e,g。 如果有人去了url: example.com/js/foo.jar 然后我需要将其正确地作为javascript文件提供。 同时,如果有人去: example.com/bar 我需要将Struts2作为可能的控制器来提供服务。 我在网上发现的从url中删除后缀的方法会导致两个URl由struts 2提供(因此即使它存在,也会给第一个foo.js文件带来错误)。 是否有一种方法(如拦截器)在发出错误之前首先检查给定的.js文件是否存在?

Spring MVC页面HTTP状态400和不正确的URL

我遇到了应用程序的一些问题。 我有一个注册表格,从控制器发布到另一页面,此页面显示注册表格中的查询结果。 在结果页面上,我选择一条记录,然后将数据返回到注册页面。 用户应该能够在返回记录后更新记录或再次执行查询。 我遇到的问题是当用户在注册表单上并执行查询时,他们被发布到结果页面,显示结果页面但是url没有改变。 注册url为http://localhost:8084/crimeTrack/citizen_registration.htm当点击http://localhost:8084/crimeTrack/citizen_registration.htm时,点击查询按钮,url仍然是http://localhost:8084/crimeTrack/citizen_registration.htm /在结果页面上选择/有几条记录,用户被发回到具有所选记录的注册页面,并显示该用户现在再次执行更新或查询,url为http://localhost:8084/crimeTrack/getCitizen/1985121244.htm ,用户现在在注册页面上。 如果我再次单击查询/更新,我收到HTTP 400错误 ,并且URL正在读取http://localhost:8084/crimeTrack/getCitizen/citizen_registration.htm/ ,这不是Controller中的有效URL映射。 我认为当请求注册页面时,url应为http://localhost:8084/crimeTrack/citizen_registration.htm 。 我不确定结果页面中的POST何时将用户带回注册页面的URL应为http://localhost:8084/crimeTrack/getCitizen/1985121244.htm附加的号码是公民号码。 在我的代码下面,我不确定我是否正确地进行了这些调用,我想对我得到的结果进行解释以及解决所遇到的问题; 使用jquery提交页面: 这是注册页面的示例,所有其他页面遵循相同的模式 JScript中 function submitPage(){ document.getElementById(“citizenRegistration”).action=”citizen_registration.htm”; //document.getElementById(“citizenRegistration”).target=”_self”; document.getElementById(“citizenRegistration”).method = “POST”; document.getElementById(“citizenRegistration”).submit(); } citizen_registration.jsp Citizen Registration …………………… citizenList.jsp function submitPage(socialSecurityNumber){ document.getElementById(“citizenList”).action=”getCitizen/1985121244.htm”;//harded coded for testing //document.getElementById(“citizenList”).target=”_self”; document.getElementById(“citizenList”).method = “POST”; document.getElementById(“citizenList”).submit(); } function GetCitizenTypeDescription(citizenTypeId){ $.ajax({ type:’GET’, url:’getCitizenTypeDescription.htm’, data:{citizenTypeId:citizenTypeId}, dataType: ‘text’, success: function […]

注释属性RequestMapping.value的值必须是常量表达式

使用以下代码段时: public class MyUrls { // properties get initialized using static{…} public final static String URL_HOMEPAGE = properties.getProperty(“app.homepage”); } @Controller public class HomepageController { @RequestMapping(MyUrls.URL_HOMEPAGE) public String homepage() { return “/homepage/index”; } } 我收到以下错误: The value for annotation attribute RequestMapping.value must be a constant expression 但事实上, URL_HOMEPAGE确实是一个常量,因为它被声明为public final static 。 我错了吗? 如何解决这个问题?