简体   繁体   中英

JSP and Java Servlet

I have some code. It works in JSp but not in Java servlet. I am pasting my code here. Can u plz state the mistake in servlet file?

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 Servlet :-

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");
    }
     }

Use doGet method not doPost

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}

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