-------------------------------------------------------------
package cm.example2.hasa;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
/**
* Servlet implementation class Ss
*/
public class Ss extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Ss() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
*/
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
if(request.getParameter("firstname") == null ||request.getParameter("firstname") == null){
getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
return;
}
//PrintWriter out = response.getWriter();
String fname=request.getParameter("firstname");
String lname=request.getParameter("lastname");
//out.println("Hello " +fname+ " " + lname);
Connection c = null;
Statement stmt = null;
try {
Class.forName("org.postgresql.Driver");
c = DriverManager.getConnection("jdbc:postgresql://192.168.43.135:5432/PGRS1","postgres","123456");
c.setAutoCommit(false);
System.out.println("Opened database successfully");
stmt = c.createStatement();
ResultSet rs = stmt.executeQuery( "SELECT * from sc1.tb1;" );
while ( rs.next() ) {
fname = rs.getString("fname");
lname = rs.getString("lname");
System.out.println( "FNAME = " + fname );
System.out.println( "LNAME = " + lname );
System.out.println();
}
rs.close();
stmt.close();
c.close();
} catch ( Exception e ) {
//System.err.println( e.getClass().getName()+": "+ e.getMessage() );
// System.exit(0);
System.out.println("not Opened database ");
}
request.setAttribute("fname", fname);
request.setAttribute("lname", lname);
getServletContext().getRequestDispatcher("/output.jsp").forward(request, response);
}
}
======================================
output.jsp
----------------------
<body>
<h1>Your name is </h1>
<%
String fname=(String) request.getAttribute("fname");
String lname=(String) request.getAttribute("lname");
out.print(fname+" "+lname);
%>
</body>
========================================
index.jsp
-----------------------
<body>
<form action="ss" method="post">
<table border="0">
<tr>
<td>First Name : </td> <td> <input type="text" name="firstname" /> </td>
</tr>
<tr>
<td>Last Name: </td> <td> <input type="text" name="lastname" /> </td>
</tr>
<tr>
<td colspan="2"> <input type="submit" value="Submit" /> </td>
</tr>
</table>
</form>
</body>
==================================================
import all warning marks as .sql suggestions
==================================================
import all warning marks as .sql suggestions
==================================================
first of all
download jdbc
https://jdbc.postgresql.org/download.html
http://www.tutorialspoint.com/postgresql/postgresql_java.htm
========================
simple authentication
create postgres-ds.xml file in \jboss-4.0.3SP1\server\default\deploy\
<?xml version="1.0" encoding="UTF-8"?>
<!-- ===================================================================== -->
<!-- -->
<!-- JBoss Server Configuration -->
<!-- -->
<!-- ===================================================================== -->
<!-- $Id: postgres-ds.xml,v 1.1.2.1 2003/09/05 16:38:24 patriot1burke Exp $ -->
<!-- ==================================================================== -->
<!-- Datasource config for Postgres -->
<!-- ==================================================================== -->
<datasources>
<local-tx-datasource>
<jndi-name>PostgresDS</jndi-name>
<connection-url>jdbc:postgresql://192.168.0.234:5432/PGRS1</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<user-name>postgres</user-name>
<password>123456</password>
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
Following code is OPTIONAL
-->
<check-valid-connection-sql>select 1</check-valid-connection-sql>
<min-pool-size>3</min-pool-size>
<max-pool-size>80</max-pool-size>
<blocking-timeout-millis>15000</blocking-timeout-millis>
<idle-timeout-minutes>15</idle-timeout-minutes>
<!-- sql to call on an existing pooled connection when it is obtained from pool
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
-->
</local-tx-datasource>
</datasources>
======================
index.jsp
<body>
<form action="ss" method="post">
<table border="0">
<tr>
<td>User Name : </td> <td> <input type="text" name="firstname" /> </td>
</tr>
<tr>
<td>Password : </td> <td> <input type="text" name="lastname" /> </td>
</tr>
<tr>
<td colspan="2"> <input type="submit" value="Submit" /> </td>
</tr>
</table>
</form>
</body>
========================
output.jsp
<body>
<h1>You have login successfully</h1>
<%
String fname=(String) request.getAttribute("fname");
String lname=(String) request.getAttribute("lname");
out.print(fname+" "+lname);
%>
</body>
===========================
ACTUAL Login from with css scripts
https://www.youtube.com/watch?v=xTz_yAAgR24
-------------
DEPLOY
-------------
export war with source files
====
in to deploy location, copy postgresds.xml file
====
if You're getting a ClassNotFoundException. The postgress driver classes
could not be found on the classpath. Put your postgresql.jar into
$JBOSS_HOME/server/all| default | minimal/lib
copy postgres jdbc jar to all lib locations
====
allow ip's to pg_hba
====
[root@hasaranga ~]# chown jboss.jboss /jboss/jboss-1/ -R
[root@hasaranga ~]# chmod 775 /jboss/jboss-1/ -R
===
*******************************************************
copy jdbc jar as above mentioned example in the eclipse.
*******************************************************
CSS ADDING
http://www.cssflow.com/snippets/facebook-login-form
download Facebook login form
add --------------->
<form ----- class="login">
<input type="text" placeholder="Password" name="lastname" class="login-input" />
<input type="submit" value="Submit" class="login-submit"/>
========================
simple authentication
create postgres-ds.xml file in \jboss-4.0.3SP1\server\default\deploy\
<?xml version="1.0" encoding="UTF-8"?>
<!-- ===================================================================== -->
<!-- -->
<!-- JBoss Server Configuration -->
<!-- -->
<!-- ===================================================================== -->
<!-- $Id: postgres-ds.xml,v 1.1.2.1 2003/09/05 16:38:24 patriot1burke Exp $ -->
<!-- ==================================================================== -->
<!-- Datasource config for Postgres -->
<!-- ==================================================================== -->
<datasources>
<local-tx-datasource>
<jndi-name>PostgresDS</jndi-name>
<connection-url>jdbc:postgresql://192.168.0.234:5432/PGRS1</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<user-name>postgres</user-name>
<password>123456</password>
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
Following code is OPTIONAL
-->
<check-valid-connection-sql>select 1</check-valid-connection-sql>
<min-pool-size>3</min-pool-size>
<max-pool-size>80</max-pool-size>
<blocking-timeout-millis>15000</blocking-timeout-millis>
<idle-timeout-minutes>15</idle-timeout-minutes>
<!-- sql to call on an existing pooled connection when it is obtained from pool
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
-->
</local-tx-datasource>
</datasources>
======================
index.jsp
<body>
<form action="ss" method="post">
<table border="0">
<tr>
<td>User Name : </td> <td> <input type="text" name="firstname" /> </td>
</tr>
<tr>
<td>Password : </td> <td> <input type="text" name="lastname" /> </td>
</tr>
<tr>
<td colspan="2"> <input type="submit" value="Submit" /> </td>
</tr>
</table>
</form>
</body>
========================
output.jsp
<body>
<h1>You have login successfully</h1>
<%
String fname=(String) request.getAttribute("fname");
String lname=(String) request.getAttribute("lname");
out.print(fname+" "+lname);
%>
</body>
===========================
ACTUAL Login from with css scripts
https://www.youtube.com/watch?v=xTz_yAAgR24
-------------
DEPLOY
-------------
export war with source files
====
in to deploy location, copy postgresds.xml file
====
if You're getting a ClassNotFoundException. The postgress driver classes
could not be found on the classpath. Put your postgresql.jar into
$JBOSS_HOME/server/all| default | minimal/lib
copy postgres jdbc jar to all lib locations
====
allow ip's to pg_hba
====
[root@hasaranga ~]# chown jboss.jboss /jboss/jboss-1/ -R
[root@hasaranga ~]# chmod 775 /jboss/jboss-1/ -R
===
*******************************************************
copy jdbc jar as above mentioned example in the eclipse.
*******************************************************
CSS ADDING
http://www.cssflow.com/snippets/facebook-login-form
download Facebook login form
add --------------->
<form ----- class="login">
<input type="text" placeholder="Password" name="lastname" class="login-input" />
<input type="submit" value="Submit" class="login-submit"/>
<p class="login-help"><a href="">forgot password</a> </p>
copy------>
css and scss 2 folders in to Web Content in eclipse
******************************************************
copy------>
css and scss 2 folders in to Web Content in eclipse
******************************************************
ss java serverlet
===================
if(request.getParameter("firstname") == null ||request.getParameter("firstname") == null){
getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
return;
}
//PrintWriter out = response.getWriter();
String fbname=request.getParameter("firstname");
String lbname=request.getParameter("lastname");
//out.println("Hello " +fname+ " " + lname);
String fname=null;
String lname=null;
Connection c = null;
Statement stmt = null;
try {
////////
javax.naming.Context ic = new javax.naming.InitialContext();
javax.naming.Context ctx = (javax.naming.Context) ic.lookup("java:");
javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("PostgresDS");
java.sql.Connection con = ds.getConnection();
/////////
//// Class.forName("org.postgresql.Driver");
////c = DriverManager.getConnection("jdbc:postgresql://192.168.0.234:5432/PGRS1","postgres","123456");
con.setAutoCommit(false);
System.out.println("Opened database successfully");
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery( "SELECT * from sc1.tb1 where sc1.tb1.fname='"+fbname+"';" );
while ( rs.next() ) {
// fname = rs.getString("fname");
lname = rs.getString("lname");
}
rs.close();
stmt.close();
con.close();
// System.out.println( "FNAME = " + fname );
System.out.println( "LNAME = " + lname );
System.out.println();
if(lbname.equals(lname)){
request.setAttribute("fname", fbname);
request.setAttribute("lname", lbname);
getServletContext().getRequestDispatcher("/output.jsp").forward(request, response);
}
else{
System.out.println( "ERROR...");
}
} catch ( Exception e ) {
//System.err.println( e.getClass().getName()+": "+ e.getMessage() );
// System.exit(0);
System.out.println("not Opened database ");
}
============================================
index.jsp
---------------------
<body>
<form action="ss" method="post" class="login">
<!--<img src="<%=request.getContextPath()%>/WebContent/WEB-INF/lib/one.jpg"/> --->
<table border="0">
<tr>
<td> <input type="text" placeholder="User Name" name="firstname" class="login-input" /> </td>
</tr>
<tr>
<td> <input type="text" placeholder="Password" name="lastname" class="login-input" /> </td>
</tr>
<tr>
<td colspan="2"> <input type="submit" value="Submit" class="login-submit"/> </td>
</tr>
<tr>
<td> <p class="login-help"><a href="">forgot password</a> </p></td>
</tr>
</table>
</form>
</body>
===============================
output.jsp
-------------
<body>
<h1>You have login successfully</h1>
<%
String fname=(String) request.getAttribute("fname");
String lname=(String) request.getAttribute("lname");
out.print(fname+" "+lname);
%>
</body>
No comments:
Post a Comment