Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Malformed Servlet

 
shabbir zakir
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI!
THe above code compiles properly but when i start my server it gives malformedValidatePinServlet and i can not start that servlet from my browser though my path is right. The code is as below
import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ValidateServlet extends HttpServlet
{
public static final String PREFIX = "ijs.session.login";
public static final String ACCOUNT = PREFIX + ".account";

public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
PrintWriter out = response.getWriter();
response.setContentType("text/html");

HttpSession session = request.getSession(true);
session.removeValue(ACCOUNT);
try{
String acctno = request.getParameter("acctno");
if(acctno == null)
throw new RuntimeException
("NO accopunt number was specified");
acctno = acctno.trim();
if(acctno.equals(""))
throw new RuntimeException
("Account number can not be blank");

String PIN = request.getParameter("PIN");
if(PIN == null)
throw new RuntimeException
("NO PIN number was specified");

PIN = PIN.trim();
if(PIN.equals(""))
throw new RuntimeException
("PIN number cannot be balnk");

if(!PIN.equals("4311"))
throw new RuntimeException
("Invalid PIN number");

Hashtable account = new Hashtable();
account.put("acctno",acctno);
account.put("PIN",PIN);
session.putValue(ACCOUNT,account);

StringBuffer buffer = new StringBuffer();

buffer.append("<H3>Welcome to ServletBank</h3>");
buffer.append("Please select from");
buffer.append(" the following options");
buffer.append("<ol>");
buffer.append("<LI>");
buffer.append("<A HREF=\"http://localhost:8080/examples/servlet/BalanceInquiry\"");
buffer.append(">Balance Inquiry</A>");
buffer.append("<L1>Transfer Funds");
buffer.append("(not available at the moment)");
buffer.append("<ol>");

out.println(buffer.toString());
}
catch(RuntimeException e)
{
StringBuffer buffer = new StringBuffer();

buffer.append("<H3>Welcome to ServletBank</h3>");
buffer.append("<PRE>\n");
buffer.append(e.getMessage());
buffer.append("\n");
buffer.append("</PRE>");
buffer.append("<P>");
buffer.append("Click");
buffer.append("<A href=\"");
buffer.append("/ijs/Chap07/login/GetAccountNumber.html\"");
buffer.append(">here</A>");
buffer.append(" to enter your account number.");

out.println(buffer.toString());
}
finally {
out.flush();
}
}

public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
doGet(request,response);
} }

Thanks in adavance
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic