Wrox Programmer Forums
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics 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:07 PM
Registered User
 
Join Date: Aug 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default plz help me ASAP

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, 09:19 AM
Registered User
 
Join Date: Jun 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So, where is the problem occuring:-)?

 
Old August 22nd, 2007, 09:40 AM
Registered User
 
Join Date: Aug 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi Johnaka888,
When i run this application on server, its taking me to login.html but when i provide username and click on submit button, its not pointing to servlet where i validated the username and instead im getting " A run time error has occured". Please help me, whether there is any problem with the code in FirstServletL1. As i guess its something wrong with the servlet

 
Old August 22nd, 2007, 10:11 AM
Authorized User
 
Join Date: May 2007
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

plz try to print the expection in consol, using ordinary
printout

http://studyjava.org/forums/
 
Old August 22nd, 2007, 12:32 PM
Registered User
 
Join Date: Aug 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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






Similar Threads
Thread Thread Starter Forum Replies Last Post
plz.....plz solve out my problem.... kethireddy435 ASP.NET 1.x and 2.0 Application Design 1 October 4th, 2007 12:56 PM
Need Help ASAP coding C# 1 June 6th, 2007 12:41 AM
Plz Help ASAP phantom3008 Classic ASP Basics 3 March 2nd, 2007 05:55 PM
Plz Help ASAP phantom3008 Classic ASP Databases 33 February 16th, 2007 10:50 PM
HELP! HELP! Please ASAP iamucha Access 2 March 25th, 2004 11:42 AM





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