vaibhav patil
vaibhav patil

Reputation: 143

how to fetch request url from another server into spring mvc controller

I have one webapplication http://localhost:8080/TestWeb/ .I want to fetch url and data in my spring mvc controller e.g.

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

sample of my 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";
}

dispatcher-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>

How can I fetch request url from tes.bg7.com server into spring mvc controller?

Thanks in advance

Upvotes: 1

Views: 1505

Answers (2)

Prakash Hari Sharma
Prakash Hari Sharma

Reputation: 1424

Extending @Vaibs answer to fetch URL as well :

  @RequestMapping(value = "/login", method = RequestMethod.GET)
  public String login1(@RequestParam("sn")String sn,@RequestParam("token")Integer token,HttpServletRequest request)
  {
      String url = request.getRequestURL().toString() + "?" + request.getQueryString();
      //business logic
  }

Upvotes: 0

Vaibs
Vaibs

Reputation: 1606

use the @RequestParam for fetching the data from url. Try below code.

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

Upvotes: 1

Related Questions