将数据从jsp传递到servlet返回null

时间:2016-01-31 13:42:40

标签: java xml jsp servlets login

我的Lecturer登录表单有问题。这是我的讲师的登录表单(JSP文件),我与管理员登录表单(index.jsp)结合使用:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
 id="WebApp_ID" version="3.0"> 
  <display-name>myapp</display-name>   
  <servlet>   
    <servlet-name>LoginServlet</servlet-name>   
    <servlet-class>CSP600.LoginServlet</servlet-class> 
  </servlet>   
  <servlet-mapping>   
    <servlet-name>LoginServlet</servlet-name>   
    <url-pattern>/adminLogin</url-pattern>  
  </servlet-mapping> 
  <servlet>   
    <servlet-name>LoginLecturerServlet</servlet-name>   
    <servlet-class>CSP600.LoginLecturerServlet</servlet-class> 
  </servlet>   
  <servlet-mapping>   
    <servlet-name>LoginLecturerServlet</servlet-name>   
    <url-pattern>/lecturerLogin</url-pattern>  
  </servlet-mapping>
  <session-config>    
    <session-timeout>-1</session-timeout>  
  </session-config>
</web-app>

这是XML文件:

try {
    LecturerBean lecturer = new LecturerBean();
    lecturer.setLecturerID(request.getParameter("lecturerid"));
    lecturer.setLecturerPassword(request.getParameter("lecturerpassword"));
    lecturer = LecturerDAO.lecturerlogin(lecturer);
    if (lecturer.isValid()) {
        HttpSession session = request.getSession(true);
        session.setAttribute("currentSessionUser", lecturer);
        response.sendRedirect("homeLecturer.jsp"); // logged-in page
    }
    else {
        response.sendRedirect("invalidLogin.jsp"); // error page
    }
}
catch (Throwable theException) {
    System.out.println(theException);
}

这是我的Servlet(使用doGet):

<HorizontalScrollView 
    android:id="@+id/vTabs" 
    android:scrollbars="none" 
    android:layout_width="fill_parent" 
    android:layout_alignParentBottom="true"
    android:layout_height="wrap_content">
    <LinearLayout 
        android:orientation="horizontal" 
        android:background="@color/main_color_gray_dk" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content">
        <Button 
            android:enabled="false" 
            android:id="@+id/tab1" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:text="@string/popular" />
        <View 
            android:id="@id/view1" 
            android:layout_width="@dimen/pad_1dp" 
            android:layout_height="fill_parent" />
        <Button 
            android:id="@id/tab2" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:text="@string/newest" />
        <View 
            android:id="@id/view1" 
            android:layout_width="@dimen/pad_1dp" 
            android:layout_height="fill_parent"  />
        <Button 
            android:id="@id/tab3" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:text="@string/distance" />
        <View 
            android:id="@id/view1" 
            android:layout_width="@dimen/pad_1dp" 
            android:layout_height="fill_parent"  />
        <Button 
            android:id="@+id/tab4" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:text="@string/minimum"  />
    </LinearLayout>
</HorizontalScrollView>

我已经使用相同的代码进行管理员登录(当然我改变了必要的部分)并且它工作得很好。但是,JSP文件中的输入数据不会因未知原因而传递。因此,它向bean和DAO返回NULL。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

更改

SELECT INET_NTOA(lastip) 
From db_1.amxbans_amxadmins 
T1 INNER JOIN  db_2.mybb_users T2 ON T1.uid = T2.uid 
WHERE T2.uid = 145

 lecturer.setLecturerID(request.getParameter("lecturerid"));
lecturer.setLecturerPassword(request.getParameter("lecturerpassword"));