problem with servlet
Hi all,
Im very new to programming.
Right now im using websphere studio application developer, and im trying to code which takes username(login.html) and this parameter will pass on to servlet for validation, wherein it checks for null and if the user has given the right username then it should take him to display.jsp or else back to login.html
Below is the code i have used.
login.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="../theme/Master.css" rel="stylesheet"
type="text/css">
<TITLE>login.html</TITLE>
</HEAD>
<BODY>
<form action="/FirstServletL1" method="post">
<td>UserName:</td>
<input type="text" name="username">
<br><input type="button" value="SUBMIT">
</form>
</BODY>
</HTML>
FirstServletL1
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @version 1.0
* @author
*/
public class FirstServletL1 extends HttpServlet implements Servlet {
//private static final String LOGIN_JSP="/login.html";
//private static final String DISPLAY_JSP = "/display.jsp";
/**
* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public void doPost(HttpServletRequest req,HttpServletResponse resp)throws ServletException, IOException {
String name= req.getParameter("username");
if((name==null) || (name.length()==0)){
RequestDispatcher rd= req.getRequestDispatcher("/login.html");
rd.forward( req, resp);
}
else{
RequestDispatcher rd= req.getRequestDispatche("/display.jsp");
rd.forward( req, resp);
}
}
}
display.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="../theme/Master.css" rel="stylesheet"
type="text/css">
<TITLE>display.jsp</TITLE>
</HEAD>
<BODY>
<P>Hi, Welcome<%= request.getParameter("username")%></P>
</BODY>
</HTML>
and im not gettin any error in code and the web.xml is pointing to correct context root
|