Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 21st, 2007, 09:43 AM
Registered User
 
Join Date: Aug 2007
Location: bangalore, karnataka, India.
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

Reply With Quote
  #2 (permalink)  
Old August 23rd, 2007, 08:22 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hyderabad, A.P., India.
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

To submit a form you should use input of type submit. Change your input tag to

<input type="submit" value="SUBMIT">

from

<input type="button" value="SUBMIT">

Regards,
Rakesh
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off




All times are GMT -4. The time now is 10:40 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.