Wrox Programmer Forums
|
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE 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 17th, 2007, 12:12 PM
Registered User
 
Join Date: Aug 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default need help

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 August 22nd, 2007, 12:34 PM
Registered User
 
Join Date: Aug 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
Finally i got my problem solved by some R&D work
Thanks all..:D










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