Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet code for JSP and Servlet
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sushil
code for JSP and Servlet
2 Answer(s)      6 years and 5 months ago
Posted in : JSP-Servlet



Advertisement
View Answers

June 4, 2008 at 7:34 PM


Hi sushil,

package javacode;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class LoginAction extends HttpServlet {
private Connection con;
String url = "jdbc:mysql://192.168.10.211:3306/";;
String db = "amar";
String driver = "com.mysql.jdbc.Driver";
String userName ="amar";
String password="amar123";
public void init()throws ServletException {
System.out.println("INIT");
try {
Class.forName(driver);
con=DriverManager.getConnection(url+db,userName,password);
}//try
catch(Exception e){
e.printStackTrace();
throw new ServletException("unable to get database cooenction.");
}//catch

}//init
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException {

System.out.println("in service");
res.setContentType("text/html");
PrintWriter out=res.getWriter();
PreparedStatement ps=null;
try{
String userid=req.getParameter("userid");
String pass=req.getParameter("password");
if(userid==null||userid.equals("")||pass==null||pass.equals("")){
out.println("<html><body>");
out.println("<i>UserName/Password are empty,they cannot be empty </i>");
out.println("</body></html>");
return;
}//if
ps=con.prepareStatement("select * from login where userid=? and password=?");
ps.setString(1,userid);
ps.setString(2,pass);
ResultSet rs=ps.executeQuery();
out.println("<html><body>");
if(rs.next())
out.println("Successfully login");
else
out.println("username and password not currect, please try again.");
out.println("</body></html>");
}//try
catch(Exception e){
out.println("unable to process the request please try later");
}//catch
finally {
try{
ps.close();
}
catch(Exception e) {}
}//finally
}//doget
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException,
IOException {
doGet(req, res);
}
public void destroy() {
System.out.println("In destroy");
try {
con.close();
}
catch(Exception e) {
System.out.println(e);
}
}//destroy
}



June 4, 2008 at 7:36 PM


web.xml
--------------------

<servlet>
<servlet-name>loginaction</servlet-name>
<servlet-class>javacode.LoginAction</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>loginaction</servlet-name>
<url-pattern>/jsp/LoginAction</url-pattern>
</servlet-mapping>



----------------------------------

Read for more information.

http://www.roseindia.net/servlets

Thanks



Related Tutorials/Questions & Answers:
jsp code - JSP-Servlet
jsp code  Can anyone help me in writing jsp/servlet code to retrieve files and display in the browser from a given directory.  Hi Friend, Try the following code: Thanks
Searching for Code - JSP-Servlet
JSP, Servlet Searching for Code  Hi, i am looking for a jsp servlet code examples for the search function in my application.Thanks
Advertisements
servlet code - JSP-Servlet
servlet code  Create a servlet to develop a login application with javascript clientside validations and serverside validations
servlet code - JSP-Servlet
servlet code  how to implement paging or pagination in java code using servlets.  Hi Friend, Try the following code: import java.io.... of JSP page"); out.println(""); out.println(""); out.println
jsp code - JSP-Servlet
jsp code  sample code for change password example Old Password: new Password: confirm Password
jsp code - JSP-Servlet
jsp code  I need code for bar charts using jsp. I searched some code but they are contain some of their own packages. Please give me asimple code... friend, Code to solve the problem : Thanks
jsp code - JSP-Servlet
jsp code  sample code to create hyperlink within hyperlink example: reservation: train: A/C department non A/c Department
jsp code - JSP-Servlet
jsp code  in a jsp a table is existed ,in table each row contain one checkbox and name and desription how to delete specific rows in a table .  Hi Friend, Try the following code: 1)form.jsp: Name
jsp code - JSP-Servlet
jsp code  how to count no of clicks made on a link and save it on database( using jsp)  Hi Friend, Try the following code: 1)click.jsp var numberOfClicks = 0; function hello(){ numberOfClicks
jsp code - JSP-Servlet
jsp code  in my table there are 3 fields named orderid ,itemname, itemqty. i want code that fetch orderid in dropdown... on select dropdown get table of item details of that orderid... there are multiple items at one orderid
JSP code - JSP-Servlet
me how to link these pages with each other using JSP..and how to write the code using JSP.. requriment for Newuser: 1>fname,lastname 2>Loginname...JSP code  hello,i working in project with JSP technology,i have one
code for JSP and Servlet - JSP-Servlet
code for JSP and Servlet  i have to create a jsp page that contains username and password, so how to code servlet according to it?  Hi... -------------------- loginaction javacode.LoginAction loginaction /jsp/LoginAction
jsp code - JSP-Servlet
jsp code  how to write a code in jsp with out using servelts finding sum and avg of 40 numbers  Hi Friend, Try the following code: Thanks  Hi Friend, Do one change in the provided code.As we
JSP code - JSP-Servlet
JSP code  hi i want to clear text box fields after click on submit.... thanking u......... This is what my code is. Jam Name...;   Hi Friend, Try the following code: Jam Name
jsp code - JSP-Servlet
jsp code   the value did not passed from script and not inserted in to database in the code u given . var numberOfClicks = 0; function hello(){ numberOfClicks++; alert( numberOfClicks ); document.form1.text.value
jsp code - JSP-Servlet
jsp code  hi my requirement is generate dynamic drop down lists... statement? pls provide code how to get first selected drop down list value to generate second drop down list by using jsp? pls ?   Hi Friend
JSP Code - JSP-Servlet
JSP Code  Create a html reader JSP tag that read the html page from a link and will display the contents on the JSP. Do not use include directive
jsp code - JSP-Servlet
jsp code  i want to add below code data in mysql database using jsp... using below code we got data in text box i want to add multiple data in database... Add/Remove dynamic rows in HTML table
atm code in servlet& jsp
atm code in servlet& jsp  pls send me the code of ATM project in servlet jsp . my requirements are first of all an user login window open then balance enquiry, withdraw of money, money transfer, then log out. pls send as early
JSP Code - JSP-Servlet
JSP Code  Hi, I have a problem in limiting the number of row... to display only 10 records per pages in jsp, then how can i achieve this concept... Rai.  Hi Friend, Try the following code: Pagination
jsp code - JSP-Servlet
jsp code  hi i am doing project work i am generating time table for this i have taken form courseyear textbox semistername textbox no of periods... will be allotted to six days. pls send me code for this pls thankyou
jsp code - JSP-Servlet
jsp code  Hello Everybody, can anyone help me to findout the modules as i am developing a whiteboard application using jsp? this application is my dream application. Thank you
JSP Code - JSP-Servlet
JSP Code  Hi, Do we have a datagrid equivalent concept in JSP..., Please visit the following links: http://www.roseindia.net/jsp/data-grid.shtml http://www.roseindia.net/jsp/paging.shtml Thanks
jsp code - JSP-Servlet
jsp code  hello frns i want to display image from the database along... from database in Jsp to visit.... http://www.roseindia.net/jsp/retrieve-image.shtml http://www.roseindia.net/jsp/downloadimage.shtml Thanks
JSP code - JSP-Servlet
JSP code  Hi! Can somebody provide a line by line explanation of the following code. The code is used to upload and download an image. <... have successfully upload the file by the name of: Download /*Code
jsp code - JSP-Servlet
jsp code  i want to add and remove rows dynamically ... in that row 3 colums are there... first colum shows one number , second colum shows second... colum.  Hi Friend, Try the following code: Add/Remove
jsp code - JSP-Servlet
jsp code  how to get multi-chat client using jsp? i will be very glad if i'd get an idea from you people. thank you .  Hi Friend, Chat server is a standlone application that is made up the combination of two
jsp code - JSP-Servlet
jsp code  i want to design page into four pages 1) header to diplay 2) left page has to display hyperlink 3)right page has to display related page of hyperlink 4) bottom page has to display footer example header
jsp code - JSP-Servlet
jsp code  i want to design page into four pages 1) header to diplay 2) left page has to display hyperlink 3)right page has to display related page of hyperlink 4) bottom page has to display footer example header
Jsp code - JSP-Servlet
Jsp code   function Calculate() { var fpval; var cityamt; var newspaper; var sizeval; var city = document.form.city.value; var noofwd = document.form.Count.value; var nofw
Jsp code - JSP-Servlet
Jsp code  PlaceAd.jsp function Calculate() { var fpval; var cityamt; var newspaper; var sizeval; var city = document.form.city.value; var noofwd = document.form.Count.value
 

 

 

DMCA.com