Forums Register Login

Login Page creation help

+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
I want to know how to call a .java file(servlet) from a JSP page.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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.
We've gotta get close enough to that helmet to pull the choke on it's engine and flood his mind! Or, we could just read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1528 times.
Similar Threads
Getting root of my application?
Passing Values
login page using JSP
how to make a link readonly?
Browser Back Button
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:13:31.