gudii9
asked on
servlet example issue with method
I was trying following example getting error as inb attachment saying method wont suppoerted here.Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advanceServCR.JPG
test.html
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="AdminCheck" method="post">
Login ID <input type="text" value="user"/><br>
Password <input type="password" value="pass"/><br><br><br>
<input type="submit" value="OK"/><br>
</form>
</body>
</html>
AdminCheck.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletReques t;
import javax.servlet.http.HttpServletRespon se;
public class AdminCheck extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;c harset=UTF -8");
PrintWriter out = response.getWriter();
String a=request.getParameter("user");//Use rname for my JSP page
String b=request.getParameter("pass");//Pas sword for a JSP page
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet admincheck</title>");
out.println("</head>");
out.println("<body>");
if(a.equals("admin")&& b.equals("check"))
out.println("Enter successfully");
else
out.println("wrong");
out.println("<h1>Servlet admincheck at " + request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
}
web.xml
<?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/j2ee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_ID" version="2.4">
<servlet>
<servlet-name>Admin</servlet-name>
<servlet-class>AdminCheck</servlet-c lass>
</servlet>
<servlet-mapping>
<servlet-name>Admin</servlet-name>
<url-pattern>/AdminCheck</url-patter n>
</servlet-mapping>
</web-app>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I changed as
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletExcep tion;
import javax.servlet.http.HttpSer vlet;
import javax.servlet.http.HttpSer vletReques t;
import javax.servlet.http.HttpSer vletRespon se;
public class AdminCheck extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
processRequest(req, res);
/*PrintWriter pw = res.getWriter();
pw.println("<hr/>");
pw.println("Thank You for Shopping at BuyForLess.com. Please Visiting again. Hava a nice day!");*/
}
protected void processRequest(HttpServlet Request request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("t ext/html;c harset=UTF -8");
PrintWriter out = response.getWriter();
String a=request.getParameter("us er");//Use rname for my JSP page
String b=request.getParameter("pa ss");//Pas sword for a JSP page
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Servle t admincheck</title>");
out.println("</head>");
out.println("<body>");
if(a.equals("admin")&& b.equals("check"))
out.println("Enter successfully");
else
out.println("wrong");
out.println("<h1>Servlet admincheck at " + request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
}
but still coming empty servlet. PLEase advise
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletExcep
import javax.servlet.http.HttpSer
import javax.servlet.http.HttpSer
import javax.servlet.http.HttpSer
public class AdminCheck extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
processRequest(req, res);
/*PrintWriter pw = res.getWriter();
pw.println("<hr/>");
pw.println("Thank You for Shopping at BuyForLess.com. Please Visiting again. Hava a nice day!");*/
}
protected void processRequest(HttpServlet
throws ServletException, IOException {
response.setContentType("t
PrintWriter out = response.getWriter();
String a=request.getParameter("us
String b=request.getParameter("pa
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Servle
out.println("</head>");
out.println("<body>");
if(a.equals("admin")&& b.equals("check"))
out.println("Enter successfully");
else
out.println("wrong");
out.println("<h1>Servlet admincheck at " + request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
}
but still coming empty servlet. PLEase advise
ASKER
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletReques t;
import javax.servlet.http.HttpServletRespon se;
public class AdminCheck extends HttpServlet {
/*protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
processRequest(req, res);
PrintWriter pw = res.getWriter();
pw.println("<hr/>");
pw.println("Thank You for Shopping at BuyForLess.com. Please Visiting again. Hava a nice day!");
}*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;c harset=UTF -8");
PrintWriter out = response.getWriter();
String a=request.getParameter("user");//Use rname for my JSP page
String b=request.getParameter("pass");//Pas sword for a JSP page
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet admincheck</title>");
out.println("</head>");
out.println("<body>");
if(a.equals("admin")&& b.equals("check"))
out.println("Enter successfully");
else
out.println("wrong");
out.println("<h1>Servlet admincheck at " + request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
}
Above also did not work throowing blank servlet page. Please advise
What did the log file say?
ASKER
I do not know the location of the log. What would be default tomcat log folder location. I searched on *.log files and found many entries. Please advise
ASKER
I checked following folder
C:\softwares gp\apache-tomcat-7.0.29\ap ache-tomca t-7.0.29\l ogs
which is empty. Please advise
C:\softwares gp\apache-tomcat-7.0.29\ap
which is empty. Please advise
If it's absolutely empty that's possibly not the Tomcat you're using
ASKER
How do I find the log folder relating to my tomat. Is there is a way i can see properties of server and find. Please advise
You need to look at the docs for your version of Tomcat
ASKER
>>docs for your version of Tomcat
Where can I find them. How to access them. Please advise
Where can I find them. How to access them. Please advise
ASKER
>>docs for your version of Tomcat
Where can I find them. How to access them. Please advise
Where can I find them. How to access them. Please advise
ASKER
Now HTML leading to servlet but showing empty servlet .
How can I call processRequest method from doPost() method. Please advise
EmptySErvlet.JPG