REST服务未注册表单数据

时间:2013-11-16 21:54:27

标签: javascript web-services rest

我正在设计一个REST服务,允许学生登录并注册一个网站,列出他们可以使用的课程,但我仍然坚持让学生登录或注册。当我尝试甚至在firebug中获取控制台来检索学生时,这是标题响应。当我尝试注册时,我甚至没有得到响应头。

GET http://localhost:8080/CP/CoursePlanner/Planner_Service/Students/rlstric1
/CP/ (line 16) //line 16 is xmlhttp.send();
HeadersCookies
Request Headers
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Content-Type    applicaion/x-www-form-urlencoded
Cookie  __iswl_localhost:8080=0
Host    localhost:8080
Referer http://localhost:8080/CP/
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0

的Javascript

function getStudentByEmail(url) {
        var username = document.getElementById("studform").studentusername.value;
        url = url + username;
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.open("GET", url, true)
        xmlhttp.setRequestHeader("Content-type", "applicaion/x-www-form-urlencoded");
        xmlhttp.send();
    }

HTML

<form id="studform" method="GET">
    Enter student username:  <input type="text" id="studentusername" value="rlstric1">
    Enter password:       <input type="password" id="studentpass" value="test">
    <button id="login" onclick=getStudentByEmail("http://localhost:8080/CP/CoursePlanner/Planner_Service/Students/")>Login</button>
    </form>

这是我为策划者提供的服务。全局@Path是Course_Planner。我将密码硬编码为“test”。

@Path("/Students/{username}")
    @GET
    @Produces("text/html")
    @Consumes("application/x-www-form-urlencoded")
    public static String loginStudentByUsername(@PathParam("{username}") String username)
    {
        PlannerFacade pf = new PlannerFacade();
        Student x = pf.getStudentByUsername(username, "test");
        return x.toString();
    }

这是Facade方法

public Student getStudentByUsername(String username, String password)
    {
        Student stud = null;
        try
        {
            String x = password;
            ResultSet rs = null;
            PreparedStatement stmt = con.prepareStatement("SELECT password FROM Students WHERE password=?");
            stmt.setString(1, password);
            rs = stmt.executeQuery();
            if(rs.next())
            {
                password = rs.getString("password");
                if(!x.equalsIgnoreCase(password))
                {
                    return null;
                }
                else
                {
                    stmt = con.prepareStatement("SELECT Lastname, Firstname, Email, ID, Major, password FROM Students WHERE username=?");
                    stmt.setString(1,username);
                    rs = stmt.executeQuery();
                    if (rs.next()) {
                        String lname = rs.getString("Lastname");
                        String fname = rs.getString("Firstname");
                        String email = rs.getString("Email");
                        int ID = rs.getInt("ID");
                        String major = rs.getString("Major");
                        stud = new Student(lname, fname, email, ID, major, password);
                    }
                    return stud;
                }
            }
        }catch(SQLException e)
        {
            e.printStackTrace();
        }
        return stud;
    }

花了8个小时试图让学生出现在警报中();我甚至无法从DB中获取,更不用说让某人注册了..

1 个答案:

答案 0 :(得分:0)

我发现如果我正在部署我的REST服务,我不能只刷新页面。从Eclipse部署之后,我必须在apache中手动停止并启动已部署的包,然后它可以正常工作。由于某些原因,部署后刷新页面会导致引用错误,即使新部署的包处于活动状态也是如此。我确定这是新部署的包,因为我会改变

中的字母

标签,它们会在刷新时发生变化。

哦,我解决了我的问题。