package net.shopxx.aa;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.shopxx.util.JsonUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@Controller("androidController")
@RequestMapping("/user")
public class LoginControl {
@RequestMapping(value="/signin", method = RequestMethod.POST)
public @ResponseBody
String login(String name,String password) {
System.out.print("....\n");
String j="hello";
return JsonUtils.toJson(j);
}
上边是代码,没有具体功能的,我只需要Android端能连接上去服务端就可以了
应该是你的路由规则可能没有匹配上。/signin
你android提交的URL是否符合你的路由规则
public void testHttpUrlPost()
{
String name = "zh";
try {
URL url = new URL("http://192.168.3.97:8080/user/signin.jhtml");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
StringBuilder params = new StringBuilder();
params.append("name="+name);
conn.getOutputStream().write(params.toString().getBytes());
InputStream input = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String line;
StringBuilder inputsb = new StringBuilder();
while((line = reader.readLine())!= null)
{
inputsb.append(line);
}
System.out.println(inputsb.toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
这是我的android的代码。
会不会是因为我配置得有问题?
先用网页测测能不能请求,定位出问题在哪
同意楼上的,先用网页写一个测试,打断点看看,手机这块没怎么接触过,不太熟悉
检查一下服务de URI