Share on Google+Share on Google+

naveenkumar
naveen
1 Answer(s)      5 years ago
Posted in : WebSevices

Sir i 3 jsp pages...first one home.jsp

form name="form" class="sf-menu ul" method="post" action="check.jsp">
<table border="10">
<tr><td background="orange">Username:</td><td><input type="text" name="username"></td></tr>
<tr><td>Password:</td><td><input type="password" name="password"></td></tr>
<tr><td></td><td><input type="submit" value="Submit"></td></tr>
</table>
<a href="register.jsp"><img alt="doit" src="button_jointoday.png" height="60",width="60"></a>
<marquee class="c">this is naveen website</marquee>
</form>

</body>
</html>

then **check.jsp"

<[email protected] import="java.sql.*" import ="

 javax.servlet.RequestDispatcher;
"%>

<% String username=request.getParameter("username");
String password=request.getParameter("password");
 Class.forName("com.mysql.jdbc.Driver");
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/naveen","root","naveen");  
          Statement st=con.createStatement();
       ResultSet rs=st.executeQuery("select * from myaccount where username='"+username+"' and password='"+password+"'");
int count=0;
          while(rs.next())
          {

                   count++;
          }

                    if(count>0)
          {
                        response.sendRedirect("detail.jsp");


          }
          else
          {
                       response.sendRedirect("home.jsp?msg=Invalid Username or Password");
          }
%>

and third one is details.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import ="java.sql.*" import = "java.io.*" import="

 javax.servlet.RequestDispatcher;
    "%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<%
String username=request.getParameter("username");
String password=request.getParameter("password");
PrintWriter pw = response.getWriter();
pw.println(username);
pw.println(password);

now the problem is if i enter username and password the values are going to check.jsp due to action command ...but the values i entered is not able to get my details.jsp..

in check.jsp itself i can able to print my username and password but i want to display in third page only ple help me out...

ple how can i get values from firstjsppage to thirdjsp but action is mentioned for second jsp...any method is there any idea ple help me..both are in same package

Ads

View Answers

April 3, 2012 at 5:40 PM


You can use request.setAttribute()or session.setAttribute().

In check.jsp:

<[email protected] import="java.sql.*" %>
<[email protected] ="javax.servlet.RequestDispatcher"%>

<% String username=request.getParameter("username");
String password=request.getParameter("password");
 Class.forName("com.mysql.jdbc.Driver");
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/naveen","root","naveen");  
          Statement st=con.createStatement();
       ResultSet rs=st.executeQuery("select * from myaccount where username='"+username+"' and password='"+password+"'");
       int count=0;
          while(rs.next()){
              count++;
          }
          if(count>0){
              request.setAttribute("user",username);
              request.setAttribute("pass",password);
              RequestDispatcher dispatcher = request.getRequestDispatcher("detail.jsp");
              if (dispatcher != null){
                dispatcher.forward(request, response);
            } 
         }
          else
          {
                       response.sendRedirect("home.jsp?msg=Invalid Username or Password");
          }
%>

In details.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import ="java.sql.*" import = "java.io.*" import="javax.servlet.RequestDispatcher;"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<%
String username=request.getAttribute("user");
String password=request.getParameter("pass");
PrintWriter pw = response.getWriter();
pw.println(username);
pw.println(password);

%>

For more information, visit the following links:

http://www.roseindia.net/jsp/GetAttributeMethod.shtml

http://www.roseindia.net/jsp/jsp-form-session.shtml










Related Tutorials/Questions & Answers:
naveen
;</a> <marquee class="c">this is naveen website</marquee> <...","naveen"); Statement st=con.createStatement(); ResultSet rs...","naveen"); Statement st=con.createStatement(); ResultSet rs
Advertisements
Difference in size of .java & its respective .class file
. Could anyone suggest the reason. Thanks in advance. ~Naveen
Java Documentum - Java Magazine
Java Documentum  Hi All, Can anybody explain and provide good examples about JavaDocumentum. How can i start learning Documentum. Please help me.... Regards, Naveen   Hi friend, For read
is it necessary to have depth knowledge on servlets jsp and jdbc to learn java frameworks
is it necessary to have depth knowledge on servlets jsp and jdbc to learn java frameworks  Hi.. My name is naveen..Im planning to learn java frame works i.e., struts,hibernate and spring.. i dont have that much depth or practical
problem in sending data from one ip to another ip in JAVA
problem in sending data from one ip to another ip in JAVA  Hi guys . this is naveen kumar...i need a help. i want to connect one ip to another ip (like ping),after that i want send the data with my system(Ip) to another ip
java compilation error - Development process
java compilation error  i have a requirement in my prog where i need to create multiple references while looping is going on for example i have a for loop like for(int i=0;i<5;i++) { String s=new String("naveen"); } now
java - Java Beginners
,'Naveen',12345,[email protected]') insert proj values(1002,'Naveen',12345,[email protected]') insert proj values(1003,'Naveen',12345,[email protected]') insert proj values(1004,'Naveen',12345,[email protected]') insert proj values
file share to particular user
=DriverManager.getConnection("jdbc:odbc:naveen","naveen","naveen"); ResultSet rs = null; Statement...("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:naveen","naveen","naveen"); ResultSet rs = null; Statement st=null; st=con.createStatement
Updating rows who has same id with different values for each row from java program
(having sid 1) with "naveen" as value for sname column.And second row(having sid 1
To display suggestions in a text box - Ajax
. Thanks and Regards, Naveen   Hi friend, This can be done by using... AJAX!"); return; } var url="gethint.jsp"; url=url+"?q="+str; url=url.... Please correct me, if i did any mistake. Thanks and Regards, Naveen
The Beginners Guide to JAXB part 3
Oriented Architecture Frameworks"); article.setAuthor("Naveen Balani"... Architecture Frameworks</title> <author>Naveen Balani</author> <
Tutorials   
Java Spring Hibernate Struts Training 6 SaaS Software Solutions Every Business Owner Should Consider WebServices Study Material What is the use of MySQL, MS SQL in Web Hosting paradigm? What do you understand by Domain Parking? What is difference between UNIX Hosting and Window Hosting? Expalin the Web Hosting Bandwidth/Space/Transfer What do you understand by Virtual Hosting? How to Upload Site Online? How to register domain name for my Company? How to track how many hits my website gets? create plugins to detect suspicious ajax chrome extension what timing attack {practically}??? any one can help me in my Ph.d thesis Accessing your site How to develope web service with exachanging xml message between computers using SOAP How to Convert SOAP Web service to REST Web service In Java ? add a new wcf service code to TFS and make it available to create an MSI. of its How we can integrate ASP .net website to payment gateway using SOAP xml request and response using wsdl. input fields to reject all inconsistent characters in webconfig Search operation in JSP page Where can I find reviews of IT solutions company in India to choose from? help regarding creation of last year project Select Box question Web Services Tutorials What is SOA and Webservices? PHP webdesign Pinting restful webservice request on UI. asp.net MaxClients apache httpd.conf max connections Large File reading through Axis2 Web service reg tutorial http://www.roseindia.net/webservices/netbeans/JAX-RPCAdvanceConcepts.shtml What is Web Development? Get GMT from IP WEB SERVICES Create a Web Service in Java using Apache Axis2 and Eclipse with Oracle database driven local host sharing on same network compute Internet and Web related questions for Web Master. web technology What is webservices? wifi problem wifi problem Overriding jaxb binding at client side? How to connect one application to some othe application through Rest json Database with dotnet while playing youtube in iphone appliation, coming black screen in iphone project? programming questions Web Analytics Java Runtime Exception: 0x4F4F:524A 0x4120:5445 0x4348:0D0A Restful webservice

Ads

 
Advertisement null

Ads