简体   繁体   中英

Spring Tomcat 403 forbidden

I can't understand while send ajax request from phonegap spring return 403 error without handle request with tomcat. If use jetty embeded work cool.

my controller

@Controller
public class TestController {
    @RequestMapping(value = "/", method = RequestMethod.POST)
    public String test() {
        return "Hello";
    }
}

How i can full log requests in tomcat or how fix it from spring. In simple rest clients work cool.

   @RequestMapping(value = "/login", method = RequestMethod.GET)
public @ResponseBody Object loginUser1(HttpServletRequest req , HttpServletResponse httpServletResponse) {
    Enumeration<String> headerNames = req.getHeaderNames();

    while (headerNames.hasMoreElements()) {

        String headerName = headerNames.nextElement();
        System.out.println(headerName);

        Enumeration<String> headers = req.getHeaders(headerName);
        while (headers.hasMoreElements()) {
            String headerValue = headers.nextElement();
            System.out.println(headerValue);
        }

    }
    return "Hello";
}

@RequestMapping(value = "/login", method = RequestMethod.POST)
public @ResponseBody Object loginUser2(HttpServletRequest req , HttpServletResponse httpServletResponse) {
    Enumeration<String> headerNames = req.getHeaderNames();

    while (headerNames.hasMoreElements()) {

        String headerName = headerNames.nextElement();
        System.out.println(headerName);

        Enumeration<String> headers = req.getHeaders(headerName);
        while (headers.hasMoreElements()) {
            String headerValue = headers.nextElement();
            System.out.println(headerValue);
        }

    }
    return "Hello";
}

Get return

host 10.0.0.42:8080 connection keep-alive accept / x-requested-with com.citronium.planReview user-agent Mozilla/5.0 (Linux; U; Android 4.2.1; en-us; e2001v21_v89_gq2008s Build/JOP40D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 accept-encoding gzip,deflate accept-language en-US accept-charset utf-8, utf-16, *;q=0.7

I resolve my problem. In Servlet 3, is the direction WebSockets . Tomcat 7 try implement Servlets 3 and start websocket listener. Phonegap< not send header Origin , tomcat not resolve any strange origins as: "null, file://" and other. Use other servers or, use old tomcat. I am use tomcat 6.37. It's resolve my problem.

Probably you need as @Anders said:

@RequestMapping(value = "/", method = RequestMethod.GET)

If you want to add logging to your web application, you can add log4j , which is a good logging framework.

At applicationContext-security.xml define

<intercept-url pattern="/default-page" access="permit all">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM