0

我有一些代码。它适用于 JSp,但不适用于 Java servlet。我在这里粘贴我的代码。你能在servlet文件中说明错误吗?

JSP:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String rollno=null;
String category=null;
rollno=request.getParameter("rollno");
category=request.getParameter("category");
out.println(rollno+"\n"+category+"\n");
%>
</body>
</html>

Java 小服务程序:-

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;


import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    public class a extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws     ServletException, IOException {
            // TODO Auto-generated method stub
            PrintWriter out=response.getWriter();
            String rollno=null;
        String category=null;
        rollno=request.getParameter("rollno");
        category=request.getParameter("category");
        out.println(rollno+"\n"+category+"\n");
    }
     }
4

1 回答 1

3

使用 doGet 方法而不是 doPost

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
于 2013-01-27T12:19:49.307 回答