Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Servlets
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Servlets section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 21st, 2007, 09:46 AM
Registered User
 
Join Date: Aug 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

 
Old September 12th, 2007, 11:22 PM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

Can you post your web.xml code so that to verify whether the servlet is configured correctly?

- Rakesh





Similar Threads
Thread Thread Starter Forum Replies Last Post
Servlet Problem cziaul Servlets 2 April 28th, 2007 09:39 AM
My servlet problem saeed Servlets 1 April 10th, 2007 07:12 AM
servlet Problem discuss Servlets 3 February 6th, 2007 02:06 PM
servlet problem discuss Servlets 1 August 29th, 2006 10:03 AM
Servlet problem Ravi Kumar Servlets 1 June 20th, 2005 04:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.