• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Login Page creation help

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
tejaswini vasist
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to know how to call a .java file(servlet) from a JSP page.
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic