Servlet在简单的JSP应用程序中没有受到重视

时间:2016-04-21 20:35:33

标签: java jsp servlets

这是我的Servlet Class

package com.jsp.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/StudentRegistration")
public class UserServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        try {

            String UserName;
            UserName =(String)request.getParameter("Name");
            // System.out.println(fnameOperator);
            String condition = "where 1=1";
            condition = condition + "and student_id = " + UserName;
            System.out.println(condition);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        }
        request.getRequestDispatcher("Login.jsp").forward(request,
                response);
    }

}

查看页面以在Servlet中发布数据

<form action="StudentRegistration" method="get">
        <table>

            <tr>
                <td>Name:</td>
                <td><input type="text" name="Name" /></td>
            </tr>

            <tr>
                <td>Email:</td>
                <td><input type="text" name="Email" /></td>
            </tr>

            <tr>
                <td>Password:</td>
                <td><input type="Password" name="Password" /></td>
            </tr>

            <tr>
                <td>Gender:</td>
                <td><input type="radio" name="Gender" value="M" />Male <input
                    type="radio" name="Gender" value="F" />Female</td>
            </tr>

            <tr>
                <td>Image:</td>
                <td><input type="file" name="Image" /></td>
            </tr>


            <tr>
                <td>Resume:</td>
                <td><input type="file" name="Resume" /></td>
            </tr>


            <tr>
                <td colspan="2"><input type="submit" name="Register"
                    Value="Register" /> <input type="button" name="Reset"
                    Value="Reset" /></td>
            </tr>
        </table>
    </form>

这是我的Servlet映射

<servlet>
        <servlet-name>UserServlte</servlet-name>
        <servlet-class>com.jsp.servlet.UserServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>UserServlte</servlet-name>
        <url-pattern>/StudentRegistration</url-pattern>
    </servlet-mapping>

当我正在运行我的应用程序,并将数据从索引页面(查看页面)发布到servlet时,我找不到404页面。

我对JAVA开发非常陌生,请帮忙。

1 个答案:

答案 0 :(得分:0)

猜猜你的web.xml中有一个拼写错误

<servlet>
    <servlet-name>UserServlte</servlet-name>
    <servlet-class>com.jsp.servlet.UserServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>UserServlte</servlet-name>
    <url-pattern>/StudentRegistration</url-pattern>
</servlet-mapping>

您的servlet类名为UserServlet,但在web.xml上,您将其称为UserServlte