gpt4 book ai didi

java - 如何从另一台服务器获取请求url到spring mvc Controller 中

转载 作者:行者123 更新时间:2023-11-30 07:17:12 25 4
gpt4 key购买 nike

我有一个网络应用程序 http://localhost:8080/TestWeb/.我想在我的 spring mvc Controller 中获取 url 和数据例如

http://tech.bg7.com/college/home.html?sn=S1&token=01535141444B88

我的 Spring Controller 示例

@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(@ModelAttribute("login") Users usr,
BindingResult result, Model model, HttpSession session,
HttpServletRequest request) {
//business logic
return "login";
}

调度程序-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">

<context:component-scan base-package="com.tech.testWeb.*" />
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/*"
cache-period="31556926"/>

<import resource="classpath:springmvc-resteasy.xml"/>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/views/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>

如何从 tes.bg7.com 服务器获取请求 url 到 spring mvc Controller 中?

提前致谢

最佳答案

使用@RequestParam从url中获取数据。尝试下面的代码。

@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(@RequestParam("sn")String sn,@RequestParam("token")Integer token)
{
//business logic
}

关于java - 如何从另一台服务器获取请求url到spring mvc Controller 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38181442/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com