Java servlet program to find larger number of given two numbers
Simple Java servlet program which accepts two numbers using the post method and displays the smaller one.
Code:
import java.io.IOException;import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class server extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
try (PrintWriter out = response.getWriter()) {
int sum;
int x,y;
String a = request.getParameter("num1");
String b = request.getParameter("num2");
x = Integer.parseInt(a);
y = Integer.parseInt(b);
if(x>y){
out.println("First number "+x+" is greater");
}
else{
out.println("Secnd number "+y+" is greater");
}
}
}
}
Comments
Post a Comment