aspose file tools*
The moose likes JSP and the fly likes Login Page creation help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Login Page creation help" Watch "Login Page creation help" New topic
Author

Login Page creation help

tejaswini vasist
Greenhorn

Joined: Apr 10, 2004
Posts: 17
Hi,
Im new to servlets and JSp.I want to create a login page askin for username and password in JSP.Then this should validate whether the user is in the database ..if so load welcome page else error page.
Im using Tomcat 4.1,jdk1.4,Mysql database.
I need this urgently so that i can get an idea how it is done and move on.
I need the entire source code and running instructions.I do not know how it should be done.
Please somebody help!!
[ April 10, 2004: Message edited by: Bear Bibeault ]
[ April 10, 2004: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

You will get better response if you attempt to work this out and ask for help on where you are getting stuck, rather than just asking someone to write code for you for free.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
tejaswini vasist
Greenhorn

Joined: Apr 10, 2004
Posts: 17
I want to know how to call a .java file(servlet) from a JSP page.
Gert Cuppens
Ranch Hand

Joined: Jul 13, 2003
Posts: 87
In most cases, it's the other way round : a servlet calls a JSP.
The MVC (Model View Controller) model 2 states that the Controller should be a servlet where the view (or presentation) should be dealt with by a JSP.
How does a servlet call a JSP ?
Well, first of all, you should know that Tomcat does the first calling. If you have a Java web application, this application should have a web.xml file. In this web.xml file you should put the name of the servlet and the URL to which it responds.
ANd then the application gets on its way : Tomcat calls the servlet and the servlet calls its first JSP. And this could well be a login.jsp.
The communication between the servlet and JSP is done by Java Beans.
When you ask a user to log in, Tomcat calls the servlet, the servlet calls the login.jsp. When the user submits his data (username and pasword) via a submit button, the data he/she has filled in in the FORM is transmitted to the servlet. And with this data, the servlet can decide whether the user can be granted access.
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
Please try to write some code and if you find any problems then discuss it. Don't try to post your school/college assignments here. Thanks
Rajaguru Ramalingam
Greenhorn

Joined: Apr 12, 2004
Posts: 11
Tejaswini,
You need , one jsp,one servlet.
In the jsp page, put two text boxes and a submit button and in the form action..leads to the servlet. In the servlet service method..check the username and pwd validity by querying the database..if exists..use sendredirect funtion to redirect the browser to the welcome page other wise to the error page...if the user id , password are correct then , store them in the session..so that..in every successive page, we can check the user validity..so user can not be allowed to access the other pages by directly putting the url in the browser...
Practise it ..then only u will realise the thing.
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
You can call a Servlet from JSP by following the steps below
1 - Make a Servlet, lets suppose your servlet name is MySimpleServlet
2- Add the Servlet information in web.xml file by using following tags
<servlet>
<servlet-name>mysimpleservlet</servlet-name>
<servlet-class>your_package_name.MySimpleServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>mysimpleservlet</servlet-name>
<url-pattern>/mysimpleservlet</url-pattern>
</servlet-mapping>

3 - Now call the servlet from your jsp as following
<form action="/mysimpleservlet" method="GET or POST">
Thats how you can call a Servlet from JSP. If there occur any problem, feel free to post reply.
tejaswini vasist
Greenhorn

Joined: Apr 10, 2004
Posts: 17
Thanks a lot every one..i got the hang of it.
I have another doubt...wot should be done if i have to display data from the database in my JSP on page load.
Thank You.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

Originally posted by tejaswini vasist:
Thanks a lot every one..i got the hang of it.
I have another doubt...wot should be done if i have to display data from the database in my JSP on page load.
Thank You.

Call a servlet that loads the DB info and then foward to the JSP.


GenRocket - A Test Data Generation Platform
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Login Page creation help
 
Similar Threads
Browser Back Button
login page using JSP
Getting root of my application?
Passing Values
how to make a link readonly?