diff --git a/CustomerData/.classpath b/CustomerData/.classpath new file mode 100644 index 0000000..fceb480 --- /dev/null +++ b/CustomerData/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/CustomerData/.project b/CustomerData/.project new file mode 100644 index 0000000..779d5d1 --- /dev/null +++ b/CustomerData/.project @@ -0,0 +1,17 @@ + + + CustomerData + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/CustomerData/.settings/org.eclipse.jdt.core.prefs b/CustomerData/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/CustomerData/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/CustomerData/bin/HashMapDemo.class b/CustomerData/bin/HashMapDemo.class new file mode 100644 index 0000000..ff12010 Binary files /dev/null and b/CustomerData/bin/HashMapDemo.class differ diff --git a/CustomerData/bin/ReferenceObject.class b/CustomerData/bin/ReferenceObject.class new file mode 100644 index 0000000..148f06f Binary files /dev/null and b/CustomerData/bin/ReferenceObject.class differ diff --git a/CustomerData/bin/Test.class b/CustomerData/bin/Test.class new file mode 100644 index 0000000..14e1ac9 Binary files /dev/null and b/CustomerData/bin/Test.class differ diff --git a/CustomerData/src/HashMapDemo.java b/CustomerData/src/HashMapDemo.java new file mode 100644 index 0000000..927ebde --- /dev/null +++ b/CustomerData/src/HashMapDemo.java @@ -0,0 +1,34 @@ +import java.util.*; + +public class HashMapDemo { + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public static void main(String[] args) { + // TODO Auto-generated method stub + LinkedHashMap m=new LinkedHashMap(); + m.put("chandra",101); + m.put("Anil",302); + m.put("venu",203); + m.put("Dhana",402); + System.out.println(m); + /*System.out.println(m.put("venu",800)); + Set s=m.keySet(); + System.out.println(s); + Collection c= m.values(); + System.out.println(c); + Set s1=m.entrySet(); + System.out.println(s1); + Iterator itr= s1.iterator(); + while(itr.hasNext()){ + Map.Entry m1=(Map.Entry)itr.next(); + System.out.println(m1.getKey()+"----"+m1.getValue()); + if(m1.getKey().equals("Dhana")){ + m1.setValue(2000); + } + // System.out.println(m); + } + System.out.println(m);*/ + + } + +} diff --git a/CustomerData/src/ReferenceObject.java b/CustomerData/src/ReferenceObject.java new file mode 100644 index 0000000..769e0f3 --- /dev/null +++ b/CustomerData/src/ReferenceObject.java @@ -0,0 +1,25 @@ + +public class ReferenceObject { + private String name; + private String email; + private String phone; +public String getName() { + return name; +} +public void setName(String name) { + this.name = name; +} +public String getEmail() { + return email; +} +public void setEmail(String email) { + this.email = email; +} +public String getPhone() { + return phone; +} +public void setPhone(String phone) { + this.phone = phone; +} + +} diff --git a/CustomerData/src/Test.java b/CustomerData/src/Test.java new file mode 100644 index 0000000..1e0c3b1 --- /dev/null +++ b/CustomerData/src/Test.java @@ -0,0 +1,25 @@ +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.Date; + +public class Test { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + ZoneId myZone=ZoneId.systemDefault(); + Date date = new Date(); + Instant now = date.toInstant(); + LocalDateTime dateTime = LocalDateTime.ofInstant(now, myZone); + ZonedDateTime zdt = ZonedDateTime.ofInstant(now, myZone); + System.out.println(now); + System.out.println(dateTime); + System.out.println(zdt); + System.out.println(date); + + + } + +} diff --git a/DaoDemoTest/.classpath b/DaoDemoTest/.classpath new file mode 100644 index 0000000..eefbe53 --- /dev/null +++ b/DaoDemoTest/.classpath @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DaoDemoTest/.project b/DaoDemoTest/.project new file mode 100644 index 0000000..6b31a2b --- /dev/null +++ b/DaoDemoTest/.project @@ -0,0 +1,42 @@ + + + DaoDemoTest + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/DaoDemoTest/.settings/.jsdtscope b/DaoDemoTest/.settings/.jsdtscope new file mode 100644 index 0000000..92e666d --- /dev/null +++ b/DaoDemoTest/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/DaoDemoTest/.settings/org.eclipse.jdt.core.prefs b/DaoDemoTest/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..6e80039 --- /dev/null +++ b/DaoDemoTest/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/DaoDemoTest/.settings/org.eclipse.m2e.core.prefs b/DaoDemoTest/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/DaoDemoTest/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/DaoDemoTest/.settings/org.eclipse.wst.common.component b/DaoDemoTest/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..69e2e75 --- /dev/null +++ b/DaoDemoTest/.settings/org.eclipse.wst.common.component @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/DaoDemoTest/.settings/org.eclipse.wst.common.project.facet.core.xml b/DaoDemoTest/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..d5aea72 --- /dev/null +++ b/DaoDemoTest/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/DaoDemoTest/.settings/org.eclipse.wst.jsdt.ui.superType.container b/DaoDemoTest/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/DaoDemoTest/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/DaoDemoTest/.settings/org.eclipse.wst.jsdt.ui.superType.name b/DaoDemoTest/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/DaoDemoTest/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/DaoDemoTest/.settings/org.eclipse.wst.validation.prefs b/DaoDemoTest/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..04cad8c --- /dev/null +++ b/DaoDemoTest/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/DaoDemoTest/WebContent/META-INF/MANIFEST.MF b/DaoDemoTest/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/DaoDemoTest/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/DaoDemoTest/WebContent/WEB-INF/web.xml b/DaoDemoTest/WebContent/WEB-INF/web.xml new file mode 100644 index 0000000..572fcd5 --- /dev/null +++ b/DaoDemoTest/WebContent/WEB-INF/web.xml @@ -0,0 +1,12 @@ + + + JspCodeDaoDemo + + index.html + index.htm + index.jsp + default.html + default.htm + default.jsp + + \ No newline at end of file diff --git a/DaoDemoTest/WebContent/customerform.jsp b/DaoDemoTest/WebContent/customerform.jsp new file mode 100644 index 0000000..78e8709 --- /dev/null +++ b/DaoDemoTest/WebContent/customerform.jsp @@ -0,0 +1,39 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +customer jsp + + +

Register

+
+ + + + + + + + + + + + + + + + + + +
ID : +
Name : +
Email : +
Phone : +
  +
+ +
+ + \ No newline at end of file diff --git a/DaoDemoTest/WebContent/dataprint.jsp b/DaoDemoTest/WebContent/dataprint.jsp new file mode 100644 index 0000000..792895c --- /dev/null +++ b/DaoDemoTest/WebContent/dataprint.jsp @@ -0,0 +1,85 @@ +<%@page import="com.examples.daodemo.Customer"%> +<%@page import="com.examples.daodemo.UserDao"%> +<%@page import="java.util.*"%> +<%@page import="java.sql.*"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +listjsp + + +

+ Add new Customer +

+

+

Customer list

+

+ + <% + Customer savedUser = (Customer) request.getAttribute("savedUser"); + if (null != savedUser) { + %> + + + + + + + + + + + + + + + <% + } + %> + + + + + + + <% + UserDao userDao = new UserDao(); + userDao.openConnection(); + List allUsers = userDao.listAllUsers(); + for (Customer user : allUsers) { + %> + + + + + + + + <% + } + %> +
idnameemailphone
<%=savedUser.getId()%><%=savedUser.getName()%><%=savedUser.getEmail()%><%=savedUser.getPhone()%>
IDNAMEEMAILPHONEEDIT/DELETE
<%=user.getId()%><%=user.getName()%><%=user.getEmail()%><%=user.getPhone()%> + + + + + +
+
+ +
+
+
+ +
+
+
+ + + + \ No newline at end of file diff --git a/DaoDemoTest/WebContent/deleteuser.jsp b/DaoDemoTest/WebContent/deleteuser.jsp new file mode 100644 index 0000000..62389a3 --- /dev/null +++ b/DaoDemoTest/WebContent/deleteuser.jsp @@ -0,0 +1,30 @@ +<%@page import="com.examples.daodemo.UserDao"%> +<%@page import="java.util.Map"%> +<%@page import="java.sql.*"%> +<%@page import="java.lang.Object"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +delete jsp + + +

+Add new Customer

+<% +Map parametermap=request.getParameterMap(); + String id = parametermap.get("id")[0].toString(); + System.out.println(id); + try { + UserDao userDao=new UserDao(); + int count=userDao.deleteUser(id); + } + catch (Exception e) { + e.printStackTrace(); + } + %> + + + \ No newline at end of file diff --git a/DaoDemoTest/WebContent/edituser.jsp b/DaoDemoTest/WebContent/edituser.jsp new file mode 100644 index 0000000..a665dde --- /dev/null +++ b/DaoDemoTest/WebContent/edituser.jsp @@ -0,0 +1,65 @@ +<%@page import="java.util.Map"%> +<%@page import="java.sql.*"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +edit jsp + + +

Edit Your details

+<% +Map parameterMap = request.getParameterMap(); + String id = parameterMap.get("id")[0].toString(); + try { + Connection con = null; + con = openConnection(); + + ResultSet rs = loadUser(id, con); + + rs.next(); + %> +

Update User:

+
+
+ + + + + + + + +
Name: +
Email: +
Phone: +
  + + + +
+ <%} + catch (Exception e) { + e.printStackTrace(); + } %> + <%! + private ResultSet loadUser(String id,Connection con) throws SQLException { + String qry = "SELECT * FROM empdb.jspdata where ID=?"; + PreparedStatement ps = con.prepareStatement(qry); + ps.setString(1, id); + ResultSet rs = ps.executeQuery(); + return rs; + } + + private Connection openConnection() throws ClassNotFoundException, SQLException { + Connection con; + Class.forName("com.mysql.jdbc.Driver"); + con = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb", "root", "root"); + System.out.println("connection success"); + return con; + } %> + + + \ No newline at end of file diff --git a/DaoDemoTest/WebContent/hello.jsp b/DaoDemoTest/WebContent/hello.jsp new file mode 100644 index 0000000..f8d8ab0 --- /dev/null +++ b/DaoDemoTest/WebContent/hello.jsp @@ -0,0 +1,16 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Welcome jsp + + +

Hello world

+Click here to register
+ +

+Click me to print..! + + \ No newline at end of file diff --git a/DaoDemoTest/WebContent/index.html b/DaoDemoTest/WebContent/index.html new file mode 100644 index 0000000..0942538 --- /dev/null +++ b/DaoDemoTest/WebContent/index.html @@ -0,0 +1,18 @@ + + + + +Welcome page + + +

+

+ Welcome to ABBURI Solutions +

+

+

+ Click me..! +

+ + \ No newline at end of file diff --git a/DaoDemoTest/WebContent/print.jsp b/DaoDemoTest/WebContent/print.jsp new file mode 100644 index 0000000..2ad79bd --- /dev/null +++ b/DaoDemoTest/WebContent/print.jsp @@ -0,0 +1,22 @@ +<%@page import="java.util.Map"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +print jsp + + +

Your details

+<% +Map parametermap=request.getParameterMap(); +String name=parametermap.get("name")[0].toString(); +String email=parametermap.get("email")[0].toString(); +String phone=parametermap.get("phone")[0].toString(); +%> +Name: <%=name%>
+Email: <%=email%>
+Phone: <%=phone%>
+ + \ No newline at end of file diff --git a/DaoDemoTest/WebContent/saveuser.jsp b/DaoDemoTest/WebContent/saveuser.jsp new file mode 100644 index 0000000..8949535 --- /dev/null +++ b/DaoDemoTest/WebContent/saveuser.jsp @@ -0,0 +1,29 @@ +<%@page import="com.examples.daodemo.UserDao"%> +<%@page import="java.util.Map"%> +<%@page import="java.sql.*"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> + + + + +database jsp + + + <% + Map parametermap = request.getParameterMap(); + String id = parametermap.get("id")[0].toString(); + String name = parametermap.get("name")[0].toString(); + String email = parametermap.get("email")[0].toString(); + String phone = parametermap.get("phone")[0].toString(); + try { + UserDao userDao=new UserDao(); + int count=userDao.saveUser(id, name, email, phone); + } + catch (Exception e) { + e.printStackTrace(); + } + %> + + + + \ No newline at end of file diff --git a/DaoDemoTest/WebContent/updateuser.jsp b/DaoDemoTest/WebContent/updateuser.jsp new file mode 100644 index 0000000..e68c299 --- /dev/null +++ b/DaoDemoTest/WebContent/updateuser.jsp @@ -0,0 +1,35 @@ +<%@page import="com.examples.daodemo.UserDao"%> +<%@page import="java.util.Map"%> +<%@page import="java.sql.*"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +update page + + + <% + Map parametermap = request.getParameterMap(); + String id = parametermap.get("id")[0].toString(); + String name = parametermap.get("name")[0].toString(); + String email = parametermap.get("email")[0].toString(); + String phone = parametermap.get("phone")[0].toString(); + System.out.println(id); + out.println(name); + out.println(email); + out.println(phone); + + try { + + UserDao userDao=new UserDao(); + int count=userDao.updateUser(id, name, email, phone); + } + catch (Exception e) { + e.printStackTrace(); + } + %> + + + \ No newline at end of file diff --git a/DaoDemoTest/WebContent/wallpaper.jpg b/DaoDemoTest/WebContent/wallpaper.jpg new file mode 100644 index 0000000..fe33c72 Binary files /dev/null and b/DaoDemoTest/WebContent/wallpaper.jpg differ diff --git a/DaoDemoTest/build/classes/com/examples/daodemo/BaseDao.class b/DaoDemoTest/build/classes/com/examples/daodemo/BaseDao.class new file mode 100644 index 0000000..20bc4ea Binary files /dev/null and b/DaoDemoTest/build/classes/com/examples/daodemo/BaseDao.class differ diff --git a/DaoDemoTest/build/classes/com/examples/daodemo/Customer.class b/DaoDemoTest/build/classes/com/examples/daodemo/Customer.class new file mode 100644 index 0000000..f5fca2e Binary files /dev/null and b/DaoDemoTest/build/classes/com/examples/daodemo/Customer.class differ diff --git a/DaoDemoTest/build/classes/com/examples/daodemo/UserDao.class b/DaoDemoTest/build/classes/com/examples/daodemo/UserDao.class new file mode 100644 index 0000000..62fc1aa Binary files /dev/null and b/DaoDemoTest/build/classes/com/examples/daodemo/UserDao.class differ diff --git a/DaoDemoTest/pom.xml b/DaoDemoTest/pom.xml new file mode 100644 index 0000000..d4a4885 --- /dev/null +++ b/DaoDemoTest/pom.xml @@ -0,0 +1,41 @@ + + 4.0.0 + DaoDemoTest + DaoDemoTest + 0.0.1-SNAPSHOT + war + + src + test + + + maven-compiler-plugin + 3.3 + + 1.8 + 1.8 + + + + maven-war-plugin + 2.6 + + WebContent + false + + + + + + + junit + junit + 4.12 + + + org.hamcrest + hamcrest-core + 1.3 + + + \ No newline at end of file diff --git a/DaoDemoTest/src/com/examples/daodemo/BaseDao.java b/DaoDemoTest/src/com/examples/daodemo/BaseDao.java new file mode 100644 index 0000000..ae3a919 --- /dev/null +++ b/DaoDemoTest/src/com/examples/daodemo/BaseDao.java @@ -0,0 +1,17 @@ +package com.examples.daodemo; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class BaseDao { + String url = "jdbc:mysql://localhost:3306/empdb"; + String username = "root"; + String passwd = "root"; + public Connection openConnection() throws ClassNotFoundException, SQLException { + Connection con; + Class.forName("com.mysql.jdbc.Driver"); + con = DriverManager.getConnection(url, username, passwd); + return con; + } +} diff --git a/DaoDemoTest/src/com/examples/daodemo/Customer.java b/DaoDemoTest/src/com/examples/daodemo/Customer.java new file mode 100644 index 0000000..d7b6196 --- /dev/null +++ b/DaoDemoTest/src/com/examples/daodemo/Customer.java @@ -0,0 +1,32 @@ +package com.examples.daodemo; + +public class Customer { + private String id; + private String name; + private String email; + private String Phone; + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getPhone() { + return Phone; + } + public void setPhone(String phone) { + Phone = phone; + } + public String getEmail() { + return email; + } + public void setEmail(String email) { + this.email = email; + } +} diff --git a/DaoDemoTest/src/com/examples/daodemo/UserDao.java b/DaoDemoTest/src/com/examples/daodemo/UserDao.java new file mode 100644 index 0000000..51ff3f9 --- /dev/null +++ b/DaoDemoTest/src/com/examples/daodemo/UserDao.java @@ -0,0 +1,100 @@ +package com.examples.daodemo; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +import com.mysql.fabric.xmlrpc.base.Array; + +public class UserDao extends BaseDao { + public int saveUser(String id, String name, String email, String phone) + throws ClassNotFoundException, SQLException { + Connection con; + con = openConnection(); + String sql = "insert into empdb.jspdata(id,name,email,phone) values(?,?,?,?)"; + java.sql.PreparedStatement ps = con.prepareStatement(sql); + ps.setString(1, id); + ps.setString(2, name); + ps.setString(3, email); + ps.setString(4, phone); + int count = ps.executeUpdate(); + System.out.println("save success"); + con.close(); + return count; + } + + public Customer updateUser(String id, String name, String email, String phone) + throws SQLException, ClassNotFoundException { + Connection con = openConnection(); + String sql = "update empdb.jspdata set name ='" + name + "', email ='" + email + "', phone ='" + phone + + "' where ID ='" + id + "' "; + Statement st = con.createStatement(); + int count = st.executeUpdate(sql); + Customer updateUser = null; + System.out.println("user update success!!!!!!!!!"); + if(count>0){ + updateUser= buildUser(name, id, email, phone); + } + con.close(); + return updateUser; + } + + public int deleteUser(String id) throws ClassNotFoundException, SQLException { + Connection con = openConnection(); + String sql = "DELETE FROM EMPDB.JSPDATA where ID = ? "; + PreparedStatement ps = con.prepareStatement(sql); + ps.setString(1, id); + int deletedRowCount = ps.executeUpdate(); + System.out.println("User delete Success"); + con.close(); + return deletedRowCount; + + } + + public ResultSet loadAllUsers() throws SQLException, ClassNotFoundException { + Connection con = openConnection(); + String qry = "SELECT * FROM empdb.jspdata"; + Statement stmt = con.createStatement(); + ResultSet rs = stmt.executeQuery(qry); + System.out.println("load success"); + return rs; + } + + public List listAllUsers() throws ClassNotFoundException, SQLException { + String name; + String email; + String phone; + String id; + Customer cus; + List list = new ArrayList(); + ResultSet rs = loadAllUsers(); + while (rs.next()) { + cus = new Customer(); + id = rs.getString(1); + cus.setId(id); + name = rs.getString(2); + cus.setName(name); + email = rs.getString(3); + cus.setEmail(email); + phone = rs.getString(4); + cus.setPhone(phone); + cus=buildUser(name, id, email, phone); + list.add(cus); + } + return list; + } + public Customer buildUser(String name,String id,String email,String phone){ + Customer cus; + cus=new Customer(); + cus.setName(name); + cus.setId(id); + cus.setEmail(email); + cus.setPhone(phone); + return cus; + + } +} \ No newline at end of file diff --git a/DaoDemoTest/target/classes/com/examples/daodemo/BaseDao.class b/DaoDemoTest/target/classes/com/examples/daodemo/BaseDao.class new file mode 100644 index 0000000..20bc4ea Binary files /dev/null and b/DaoDemoTest/target/classes/com/examples/daodemo/BaseDao.class differ diff --git a/DaoDemoTest/target/classes/com/examples/daodemo/Customer.class b/DaoDemoTest/target/classes/com/examples/daodemo/Customer.class new file mode 100644 index 0000000..add1325 Binary files /dev/null and b/DaoDemoTest/target/classes/com/examples/daodemo/Customer.class differ diff --git a/DaoDemoTest/target/classes/com/examples/daodemo/UserDao.class b/DaoDemoTest/target/classes/com/examples/daodemo/UserDao.class new file mode 100644 index 0000000..a4da44e Binary files /dev/null and b/DaoDemoTest/target/classes/com/examples/daodemo/UserDao.class differ diff --git a/DaoDemoTest/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF b/DaoDemoTest/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..9e36ccc --- /dev/null +++ b/DaoDemoTest/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Built-By: ABBURI'S +Build-Jdk: 1.8.0_101 +Created-By: Maven Integration for Eclipse + diff --git a/DaoDemoTest/target/m2e-wtp/web-resources/META-INF/maven/DaoDemoTest/DaoDemoTest/pom.properties b/DaoDemoTest/target/m2e-wtp/web-resources/META-INF/maven/DaoDemoTest/DaoDemoTest/pom.properties new file mode 100644 index 0000000..1d5ee19 --- /dev/null +++ b/DaoDemoTest/target/m2e-wtp/web-resources/META-INF/maven/DaoDemoTest/DaoDemoTest/pom.properties @@ -0,0 +1,7 @@ +#Generated by Maven Integration for Eclipse +#Wed Oct 26 12:25:53 EDT 2016 +version=0.0.1-SNAPSHOT +groupId=DaoDemoTest +m2e.projectName=DaoDemoTest +m2e.projectLocation=C\:\\Users\\ABBURI'S\\workspace2\\DaoDemoTest +artifactId=DaoDemoTest diff --git a/DaoDemoTest/target/m2e-wtp/web-resources/META-INF/maven/DaoDemoTest/DaoDemoTest/pom.xml b/DaoDemoTest/target/m2e-wtp/web-resources/META-INF/maven/DaoDemoTest/DaoDemoTest/pom.xml new file mode 100644 index 0000000..d4a4885 --- /dev/null +++ b/DaoDemoTest/target/m2e-wtp/web-resources/META-INF/maven/DaoDemoTest/DaoDemoTest/pom.xml @@ -0,0 +1,41 @@ + + 4.0.0 + DaoDemoTest + DaoDemoTest + 0.0.1-SNAPSHOT + war + + src + test + + + maven-compiler-plugin + 3.3 + + 1.8 + 1.8 + + + + maven-war-plugin + 2.6 + + WebContent + false + + + + + + + junit + junit + 4.12 + + + org.hamcrest + hamcrest-core + 1.3 + + + \ No newline at end of file diff --git a/DaoDemoTest/target/test-classes/com/sample/test/UserDaoTest.class b/DaoDemoTest/target/test-classes/com/sample/test/UserDaoTest.class new file mode 100644 index 0000000..1ea9d4d Binary files /dev/null and b/DaoDemoTest/target/test-classes/com/sample/test/UserDaoTest.class differ diff --git a/DaoDemoTest/test/com/sample/test/UserDaoTest.java b/DaoDemoTest/test/com/sample/test/UserDaoTest.java new file mode 100644 index 0000000..c831b13 --- /dev/null +++ b/DaoDemoTest/test/com/sample/test/UserDaoTest.java @@ -0,0 +1,51 @@ +package com.sample.test; +import com.examples.daodemo.Customer; +import com.examples.daodemo.UserDao; + +import java.sql.ResultSet; +import java.util.List; + +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Test; + +public class UserDaoTest extends Assert { + @Test + public void saveUser() throws Exception{ + UserDao user=new UserDao(); + int count= user.saveUser("669", "anil", "anil@gmail.com", "75575585"); + assertEquals(count, 1); + } + @Test + public void shouldUpdateUser() throws Exception { + UserDao dao=new UserDao(); + Customer updatedUser =dao.updateUser("668", "venu", "chandra@gmail.com", "2758257298"); + assertNotNull(updatedUser); + } + @Test + public void shouldNotUpdateUser() throws Exception { + UserDao dao=new UserDao(); + Customer updatedUser =dao.updateUser("99", "chandra", "chandra@gmail.com", "2758257298"); + assertNull(updatedUser); + } + @Test + public void shouldDeleteUser() throws Exception { + UserDao dao=new UserDao(); + int deletedtedUser =dao.deleteUser("879"); + assertNotNull(deletedtedUser); + assertEquals(deletedtedUser,1); + } + @Test + public void shouldNotDeleteUser() throws Exception { + UserDao dao=new UserDao(); + int deletedtedUser =dao.deleteUser("32"); + assertNotNull(deletedtedUser); + assertEquals(deletedtedUser,0); + } + @Test + public void shouldListAllUsers() throws Exception { + UserDao dao=new UserDao(); + List list =dao.listAllUsers(); + assertNotNull(list); + } +} \ No newline at end of file diff --git a/HelloWorld/.classpath b/HelloWorld/.classpath new file mode 100644 index 0000000..2784a1b --- /dev/null +++ b/HelloWorld/.classpath @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/HelloWorld/.project b/HelloWorld/.project new file mode 100644 index 0000000..99d2c11 --- /dev/null +++ b/HelloWorld/.project @@ -0,0 +1,42 @@ + + + HelloWorld + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/HelloWorld/.settings/.jsdtscope b/HelloWorld/.settings/.jsdtscope new file mode 100644 index 0000000..2418123 --- /dev/null +++ b/HelloWorld/.settings/.jsdtscope @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/HelloWorld/.settings/org.eclipse.core.resources.prefs b/HelloWorld/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..97933e8 --- /dev/null +++ b/HelloWorld/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding//src/main/webapp/WEB-INF/views/welcome.jsp=UTF-8 diff --git a/HelloWorld/.settings/org.eclipse.jdt.core.prefs b/HelloWorld/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..45a6e0e --- /dev/null +++ b/HelloWorld/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/HelloWorld/.settings/org.eclipse.m2e.core.prefs b/HelloWorld/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/HelloWorld/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/HelloWorld/.settings/org.eclipse.wst.common.component b/HelloWorld/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..e3294ee --- /dev/null +++ b/HelloWorld/.settings/org.eclipse.wst.common.component @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/HelloWorld/.settings/org.eclipse.wst.common.project.facet.core.xml b/HelloWorld/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..d74c55e --- /dev/null +++ b/HelloWorld/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/HelloWorld/.settings/org.eclipse.wst.jsdt.ui.superType.container b/HelloWorld/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/HelloWorld/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/HelloWorld/.settings/org.eclipse.wst.jsdt.ui.superType.name b/HelloWorld/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/HelloWorld/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/HelloWorld/.settings/org.eclipse.wst.validation.prefs b/HelloWorld/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..04cad8c --- /dev/null +++ b/HelloWorld/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/HelloWorld/pom.xml b/HelloWorld/pom.xml new file mode 100644 index 0000000..c8209e4 --- /dev/null +++ b/HelloWorld/pom.xml @@ -0,0 +1,65 @@ + + 4.0.0 + com.abburi.spring.example + HelloWorld + war + 0.0.1-SNAPSHOT + HelloWorld Maven Webapp + http://maven.apache.org + + 1.7 + 4.3.0.RELEASE + + + + org.springframework + spring-webmvc + ${org.springframework-version} + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + + junit + junit + 3.8.1 + test + + + javax.servlet + jstl + 1.2 + + + + HelloWorld + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + ${java-version} + ${java-version} + + + + org.apache.maven.plugins + maven-war-plugin + 2.4 + + src/main/webapp + helloworld + false + + + + + + diff --git a/HelloWorld/src/main/java/com/chandra/spring/example/config/AppConfig.java b/HelloWorld/src/main/java/com/chandra/spring/example/config/AppConfig.java new file mode 100644 index 0000000..f778f60 --- /dev/null +++ b/HelloWorld/src/main/java/com/chandra/spring/example/config/AppConfig.java @@ -0,0 +1,34 @@ +package com.chandra.spring.example.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.ViewResolver; +import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.view.InternalResourceViewResolver; +import org.springframework.web.servlet.view.JstlView; + +@Configuration +@EnableWebMvc +@ComponentScan(basePackages = "com.chandra.spring.example") +public class AppConfig extends WebMvcConfigurerAdapter{ + + @Bean + public ViewResolver viewResolver() { + InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); + viewResolver.setViewClass(JstlView.class); + viewResolver.setPrefix("/WEB-INF/views/"); + viewResolver.setSuffix(".jsp"); + + return viewResolver; + } + + @Override + public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { + configurer.enable(); + } + + } + diff --git a/HelloWorld/src/main/java/com/chandra/spring/example/config/AppInitializer.java b/HelloWorld/src/main/java/com/chandra/spring/example/config/AppInitializer.java new file mode 100644 index 0000000..9784281 --- /dev/null +++ b/HelloWorld/src/main/java/com/chandra/spring/example/config/AppInitializer.java @@ -0,0 +1,25 @@ +package com.chandra.spring.example.config; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRegistration; + +import org.springframework.web.WebApplicationInitializer; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; +import org.springframework.web.servlet.DispatcherServlet; + +public class AppInitializer implements WebApplicationInitializer{ + + public void onStartup(ServletContext container) throws ServletException { + + AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); + ctx.register(AppConfig.class); + ctx.setServletContext(container); + + ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx)); + + servlet.setLoadOnStartup(1); + servlet.addMapping("/"); + } + +} diff --git a/HelloWorld/src/main/java/com/chandra/spring/example/controller/HelloController.java b/HelloWorld/src/main/java/com/chandra/spring/example/controller/HelloController.java new file mode 100644 index 0000000..f5328d0 --- /dev/null +++ b/HelloWorld/src/main/java/com/chandra/spring/example/controller/HelloController.java @@ -0,0 +1,17 @@ +package com.chandra.spring.example.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class HelloController { + + @GetMapping("/hello") + public String hello(Model model) { + //System.out.println("111111111111111"); + model.addAttribute("name", "chandra"); + //System.out.println("222222222222222222"); + return "welcome"; + } +} diff --git a/HelloWorld/src/main/webapp/WEB-INF/views/welcome.jsp b/HelloWorld/src/main/webapp/WEB-INF/views/welcome.jsp new file mode 100644 index 0000000..55d3c64 --- /dev/null +++ b/HelloWorld/src/main/webapp/WEB-INF/views/welcome.jsp @@ -0,0 +1,17 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + isELIgnored="false" pageEncoding="ISO-8859-1"%> +<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> + + + + +Insert title here + + + +

Hello World, Spring MVC

+ +

Welcome, ${name}

+ + \ No newline at end of file diff --git a/HelloWorld/src/main/webapp/WEB-INF/web.xml b/HelloWorld/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..9f88c1f --- /dev/null +++ b/HelloWorld/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,7 @@ + + + + Archetype Created Web Application + diff --git a/HelloWorld/src/main/webapp/index.jsp b/HelloWorld/src/main/webapp/index.jsp new file mode 100644 index 0000000..c38169b --- /dev/null +++ b/HelloWorld/src/main/webapp/index.jsp @@ -0,0 +1,5 @@ + + +

Hello World!

+ + diff --git a/HelloWorld/src/main/webapp/resources/css/style.css b/HelloWorld/src/main/webapp/resources/css/style.css new file mode 100644 index 0000000..af26eff --- /dev/null +++ b/HelloWorld/src/main/webapp/resources/css/style.css @@ -0,0 +1,4 @@ +@CHARSET "ISO-8859-1"; +body { + background-color: wheat; +} \ No newline at end of file diff --git a/HelloWorld/target/classes/com/chandra/spring/example/config/AppConfig.class b/HelloWorld/target/classes/com/chandra/spring/example/config/AppConfig.class new file mode 100644 index 0000000..c639ce0 Binary files /dev/null and b/HelloWorld/target/classes/com/chandra/spring/example/config/AppConfig.class differ diff --git a/HelloWorld/target/classes/com/chandra/spring/example/config/AppInitializer.class b/HelloWorld/target/classes/com/chandra/spring/example/config/AppInitializer.class new file mode 100644 index 0000000..22c4463 Binary files /dev/null and b/HelloWorld/target/classes/com/chandra/spring/example/config/AppInitializer.class differ diff --git a/HelloWorld/target/classes/com/chandra/spring/example/controller/HelloController.class b/HelloWorld/target/classes/com/chandra/spring/example/controller/HelloController.class new file mode 100644 index 0000000..7840111 Binary files /dev/null and b/HelloWorld/target/classes/com/chandra/spring/example/controller/HelloController.class differ diff --git a/HelloWorld/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF b/HelloWorld/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..9e36ccc --- /dev/null +++ b/HelloWorld/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Built-By: ABBURI'S +Build-Jdk: 1.8.0_101 +Created-By: Maven Integration for Eclipse + diff --git a/HelloWorld/target/m2e-wtp/web-resources/META-INF/maven/com.abburi.spring.example/HelloWorld/pom.properties b/HelloWorld/target/m2e-wtp/web-resources/META-INF/maven/com.abburi.spring.example/HelloWorld/pom.properties new file mode 100644 index 0000000..db6834b --- /dev/null +++ b/HelloWorld/target/m2e-wtp/web-resources/META-INF/maven/com.abburi.spring.example/HelloWorld/pom.properties @@ -0,0 +1,7 @@ +#Generated by Maven Integration for Eclipse +#Tue Nov 15 13:37:29 EST 2016 +version=0.0.1-SNAPSHOT +groupId=com.abburi.spring.example +m2e.projectName=HelloWorld +m2e.projectLocation=C\:\\Users\\ABBURI'S\\sts\\HelloWorld +artifactId=HelloWorld diff --git a/HelloWorld/target/m2e-wtp/web-resources/META-INF/maven/com.abburi.spring.example/HelloWorld/pom.xml b/HelloWorld/target/m2e-wtp/web-resources/META-INF/maven/com.abburi.spring.example/HelloWorld/pom.xml new file mode 100644 index 0000000..c8209e4 --- /dev/null +++ b/HelloWorld/target/m2e-wtp/web-resources/META-INF/maven/com.abburi.spring.example/HelloWorld/pom.xml @@ -0,0 +1,65 @@ + + 4.0.0 + com.abburi.spring.example + HelloWorld + war + 0.0.1-SNAPSHOT + HelloWorld Maven Webapp + http://maven.apache.org + + 1.7 + 4.3.0.RELEASE + + + + org.springframework + spring-webmvc + ${org.springframework-version} + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + + junit + junit + 3.8.1 + test + + + javax.servlet + jstl + 1.2 + + + + HelloWorld + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + ${java-version} + ${java-version} + + + + org.apache.maven.plugins + maven-war-plugin + 2.4 + + src/main/webapp + helloworld + false + + + + + + diff --git a/JspCodeDaoDemo/.classpath b/JspCodeDaoDemo/.classpath new file mode 100644 index 0000000..ad7aec3 --- /dev/null +++ b/JspCodeDaoDemo/.classpath @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/JspCodeDaoDemo/.project b/JspCodeDaoDemo/.project new file mode 100644 index 0000000..b1f64df --- /dev/null +++ b/JspCodeDaoDemo/.project @@ -0,0 +1,36 @@ + + + JspCodeDaoDemo + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/JspCodeDaoDemo/.settings/.jsdtscope b/JspCodeDaoDemo/.settings/.jsdtscope new file mode 100644 index 0000000..92e666d --- /dev/null +++ b/JspCodeDaoDemo/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/JspCodeDaoDemo/.settings/org.eclipse.jdt.core.prefs b/JspCodeDaoDemo/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/JspCodeDaoDemo/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/JspCodeDaoDemo/.settings/org.eclipse.wst.common.component b/JspCodeDaoDemo/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..3ea69ca --- /dev/null +++ b/JspCodeDaoDemo/.settings/org.eclipse.wst.common.component @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/JspCodeDaoDemo/.settings/org.eclipse.wst.common.project.facet.core.xml b/JspCodeDaoDemo/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..d5aea72 --- /dev/null +++ b/JspCodeDaoDemo/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/JspCodeDaoDemo/.settings/org.eclipse.wst.jsdt.ui.superType.container b/JspCodeDaoDemo/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/JspCodeDaoDemo/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/JspCodeDaoDemo/.settings/org.eclipse.wst.jsdt.ui.superType.name b/JspCodeDaoDemo/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/JspCodeDaoDemo/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/JspCodeDaoDemo/WebContent/META-INF/MANIFEST.MF b/JspCodeDaoDemo/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/JspCodeDaoDemo/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/JspCodeDaoDemo/WebContent/WEB-INF/web.xml b/JspCodeDaoDemo/WebContent/WEB-INF/web.xml new file mode 100644 index 0000000..572fcd5 --- /dev/null +++ b/JspCodeDaoDemo/WebContent/WEB-INF/web.xml @@ -0,0 +1,12 @@ + + + JspCodeDaoDemo + + index.html + index.htm + index.jsp + default.html + default.htm + default.jsp + + \ No newline at end of file diff --git a/JspCodeDaoDemo/WebContent/customerform.jsp b/JspCodeDaoDemo/WebContent/customerform.jsp new file mode 100644 index 0000000..78e8709 --- /dev/null +++ b/JspCodeDaoDemo/WebContent/customerform.jsp @@ -0,0 +1,39 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +customer jsp + + +

Register

+ + + + + + + + + + + + + + + + + + + +
ID : +
Name : +
Email : +
Phone : +
  +
+ + + + \ No newline at end of file diff --git a/JspCodeDaoDemo/WebContent/dataprint.jsp b/JspCodeDaoDemo/WebContent/dataprint.jsp new file mode 100644 index 0000000..dbad0fd --- /dev/null +++ b/JspCodeDaoDemo/WebContent/dataprint.jsp @@ -0,0 +1,64 @@ +<%@page import="com.examples.daodemo.Customer"%> +<%@page import="com.examples.daodemo.UserDao"%> +<%@page import="java.util.*"%> +<%@page import="java.sql.*"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +listjsp + + +

+ Add new Customer +

+

+

Customer list

+

+ + + + + + + + <% + UserDao userDao = new UserDao(); + userDao.openConnection(); + List allUsers = userDao.listAllUsers(); + for (Customer user : allUsers) { + %> + + + + + + + + <% + } + %> + +
IDNameEmailPhoneEDIT/DELETE
<%=user.getId()%><%=user.getName()%><%=user.getEmail()%><%=user.getPhone()%> + + + + + +
+
+ +
+
+
+ +
+
+
+ + + \ No newline at end of file diff --git a/JspCodeDaoDemo/WebContent/deleteuser.jsp b/JspCodeDaoDemo/WebContent/deleteuser.jsp new file mode 100644 index 0000000..62389a3 --- /dev/null +++ b/JspCodeDaoDemo/WebContent/deleteuser.jsp @@ -0,0 +1,30 @@ +<%@page import="com.examples.daodemo.UserDao"%> +<%@page import="java.util.Map"%> +<%@page import="java.sql.*"%> +<%@page import="java.lang.Object"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +delete jsp + + +

+Add new Customer

+<% +Map parametermap=request.getParameterMap(); + String id = parametermap.get("id")[0].toString(); + System.out.println(id); + try { + UserDao userDao=new UserDao(); + int count=userDao.deleteUser(id); + } + catch (Exception e) { + e.printStackTrace(); + } + %> + + + \ No newline at end of file diff --git a/JspCodeDaoDemo/WebContent/edituser.jsp b/JspCodeDaoDemo/WebContent/edituser.jsp new file mode 100644 index 0000000..a665dde --- /dev/null +++ b/JspCodeDaoDemo/WebContent/edituser.jsp @@ -0,0 +1,65 @@ +<%@page import="java.util.Map"%> +<%@page import="java.sql.*"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +edit jsp + + +

Edit Your details

+<% +Map parameterMap = request.getParameterMap(); + String id = parameterMap.get("id")[0].toString(); + try { + Connection con = null; + con = openConnection(); + + ResultSet rs = loadUser(id, con); + + rs.next(); + %> +

Update User:

+
+
+ + + + + + + + +
Name: +
Email: +
Phone: +
  + + + +
+ <%} + catch (Exception e) { + e.printStackTrace(); + } %> + <%! + private ResultSet loadUser(String id,Connection con) throws SQLException { + String qry = "SELECT * FROM empdb.jspdata where ID=?"; + PreparedStatement ps = con.prepareStatement(qry); + ps.setString(1, id); + ResultSet rs = ps.executeQuery(); + return rs; + } + + private Connection openConnection() throws ClassNotFoundException, SQLException { + Connection con; + Class.forName("com.mysql.jdbc.Driver"); + con = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb", "root", "root"); + System.out.println("connection success"); + return con; + } %> + + + \ No newline at end of file diff --git a/JspCodeDaoDemo/WebContent/hello.jsp b/JspCodeDaoDemo/WebContent/hello.jsp new file mode 100644 index 0000000..f8d8ab0 --- /dev/null +++ b/JspCodeDaoDemo/WebContent/hello.jsp @@ -0,0 +1,16 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Welcome jsp + + +

Hello world

+Click here to register
+ +

+Click me to print..! + + \ No newline at end of file diff --git a/JspCodeDaoDemo/WebContent/index.html b/JspCodeDaoDemo/WebContent/index.html new file mode 100644 index 0000000..0942538 --- /dev/null +++ b/JspCodeDaoDemo/WebContent/index.html @@ -0,0 +1,18 @@ + + + + +Welcome page + + +

+

+ Welcome to ABBURI Solutions +

+

+

+ Click me..! +

+ + \ No newline at end of file diff --git a/JspCodeDaoDemo/WebContent/print.jsp b/JspCodeDaoDemo/WebContent/print.jsp new file mode 100644 index 0000000..2ad79bd --- /dev/null +++ b/JspCodeDaoDemo/WebContent/print.jsp @@ -0,0 +1,22 @@ +<%@page import="java.util.Map"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +print jsp + + +

Your details

+<% +Map parametermap=request.getParameterMap(); +String name=parametermap.get("name")[0].toString(); +String email=parametermap.get("email")[0].toString(); +String phone=parametermap.get("phone")[0].toString(); +%> +Name: <%=name%>
+Email: <%=email%>
+Phone: <%=phone%>
+ + \ No newline at end of file diff --git a/JspCodeDaoDemo/WebContent/saveuser.jsp b/JspCodeDaoDemo/WebContent/saveuser.jsp new file mode 100644 index 0000000..8949535 --- /dev/null +++ b/JspCodeDaoDemo/WebContent/saveuser.jsp @@ -0,0 +1,29 @@ +<%@page import="com.examples.daodemo.UserDao"%> +<%@page import="java.util.Map"%> +<%@page import="java.sql.*"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> + + + + +database jsp + + + <% + Map parametermap = request.getParameterMap(); + String id = parametermap.get("id")[0].toString(); + String name = parametermap.get("name")[0].toString(); + String email = parametermap.get("email")[0].toString(); + String phone = parametermap.get("phone")[0].toString(); + try { + UserDao userDao=new UserDao(); + int count=userDao.saveUser(id, name, email, phone); + } + catch (Exception e) { + e.printStackTrace(); + } + %> + + + + \ No newline at end of file diff --git a/JspCodeDaoDemo/WebContent/updateuser.jsp b/JspCodeDaoDemo/WebContent/updateuser.jsp new file mode 100644 index 0000000..dd45f2d --- /dev/null +++ b/JspCodeDaoDemo/WebContent/updateuser.jsp @@ -0,0 +1,36 @@ +<%@page import="com.examples.daodemo.UserDao"%> +<%@page import="com.examples.daodemo.Customer"%> +<%@page import="java.util.Map"%> +<%@page import="java.sql.*"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +update page + + + <% + Map parametermap = request.getParameterMap(); + String id = parametermap.get("id")[0].toString(); + String name = parametermap.get("name")[0].toString(); + String email = parametermap.get("email")[0].toString(); + String phone = (String)parametermap.get("phone")[0].toString(); + System.out.println(id); + out.println(name); + out.println(email); + out.println(phone); + + try { + + UserDao userDao=new UserDao(); + Customer count=userDao.updateUser(id, name, email, phone); + } + catch (Exception e) { + e.printStackTrace(); + } + %> + + + \ No newline at end of file diff --git a/JspCodeDaoDemo/WebContent/wallpaper.jpg b/JspCodeDaoDemo/WebContent/wallpaper.jpg new file mode 100644 index 0000000..fe33c72 Binary files /dev/null and b/JspCodeDaoDemo/WebContent/wallpaper.jpg differ diff --git a/JspCodeDaoDemo/build/classes/com/examples/daodemo/BaseDao.class b/JspCodeDaoDemo/build/classes/com/examples/daodemo/BaseDao.class new file mode 100644 index 0000000..20bc4ea Binary files /dev/null and b/JspCodeDaoDemo/build/classes/com/examples/daodemo/BaseDao.class differ diff --git a/JspCodeDaoDemo/build/classes/com/examples/daodemo/Customer.class b/JspCodeDaoDemo/build/classes/com/examples/daodemo/Customer.class new file mode 100644 index 0000000..add1325 Binary files /dev/null and b/JspCodeDaoDemo/build/classes/com/examples/daodemo/Customer.class differ diff --git a/JspCodeDaoDemo/build/classes/com/examples/daodemo/UserDao.class b/JspCodeDaoDemo/build/classes/com/examples/daodemo/UserDao.class new file mode 100644 index 0000000..287bfb8 Binary files /dev/null and b/JspCodeDaoDemo/build/classes/com/examples/daodemo/UserDao.class differ diff --git a/JspCodeDaoDemo/src/com/examples/daodemo/BaseDao.java b/JspCodeDaoDemo/src/com/examples/daodemo/BaseDao.java new file mode 100644 index 0000000..ae3a919 --- /dev/null +++ b/JspCodeDaoDemo/src/com/examples/daodemo/BaseDao.java @@ -0,0 +1,17 @@ +package com.examples.daodemo; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class BaseDao { + String url = "jdbc:mysql://localhost:3306/empdb"; + String username = "root"; + String passwd = "root"; + public Connection openConnection() throws ClassNotFoundException, SQLException { + Connection con; + Class.forName("com.mysql.jdbc.Driver"); + con = DriverManager.getConnection(url, username, passwd); + return con; + } +} diff --git a/JspCodeDaoDemo/src/com/examples/daodemo/Customer.java b/JspCodeDaoDemo/src/com/examples/daodemo/Customer.java new file mode 100644 index 0000000..3d9d07d --- /dev/null +++ b/JspCodeDaoDemo/src/com/examples/daodemo/Customer.java @@ -0,0 +1,35 @@ +package com.examples.daodemo; + +public class Customer { +private String id; +private String name; +private String email; +private String Phone; +public String getId() { + return id; +} +public void setId(String id) { + this.id = id; +} +public String getName() { + return name; +} +public void setName(String name) { + this.name = name; +} +public String getPhone() { + return Phone; +} +public void setPhone(String phone) { + Phone = phone; +} +public String getEmail() { + return email; +} +public void setEmail(String email) { + this.email = email; +} + + + +} diff --git a/JspCodeDaoDemo/src/com/examples/daodemo/UserDao.java b/JspCodeDaoDemo/src/com/examples/daodemo/UserDao.java new file mode 100644 index 0000000..014e567 --- /dev/null +++ b/JspCodeDaoDemo/src/com/examples/daodemo/UserDao.java @@ -0,0 +1,105 @@ +package com.examples.daodemo; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +import com.mysql.fabric.xmlrpc.base.Array; + +public class UserDao extends BaseDao { + + public int saveUser(String id, String name, String email, String phone) + throws ClassNotFoundException, SQLException { + Connection con; + con = openConnection(); + String sql = "insert into empdb.jspdata(id,name,email,phone) values(?,?,?,?)"; + java.sql.PreparedStatement ps = con.prepareStatement(sql); + ps.setString(1, id); + ps.setString(2, name); + ps.setString(3, email); + ps.setString(4, phone); + int count = ps.executeUpdate(); + System.out.println("save success"); + con.close(); + return count; + } + + public Customer updateUser(String id, String name, String email, String phone) + throws SQLException, ClassNotFoundException { + Connection con = openConnection(); + String sql = "update empdb.jspdata set name ='" + name + "', email ='" + email + "', phone ='" + phone + + "' where ID ='" + id + "' "; + Statement st = con.createStatement(); + int count = st.executeUpdate(sql); + Customer updateUser = null; + System.out.println("user update success!!!!!!!!!"); + if(count>0){ + updateUser= buildUser(name, id, email, phone); + } + con.close(); + return updateUser; + } + + public int deleteUser(String id) throws ClassNotFoundException, SQLException { + Connection con = openConnection(); + String sql = "DELETE FROM EMPDB.JSPDATA where ID = ? "; + PreparedStatement ps = con.prepareStatement(sql); + ps.setString(1, id); + int deletedRowCount = ps.executeUpdate(); + System.out.println("User delete Success"); + con.close(); + return deletedRowCount; + + } + + public ResultSet loadAllUsers() throws SQLException, ClassNotFoundException { + Connection con = openConnection(); + String qry = "SELECT * FROM empdb.jspdata"; + Statement stmt = con.createStatement(); + ResultSet rs = stmt.executeQuery(qry); + System.out.println("load success"); + return rs; + } + + public List listAllUsers() throws ClassNotFoundException, SQLException { + String name; + String email; + String phone; + String id; + Customer cus; + List list = new ArrayList(); + Connection con = openConnection(); + String qry = "SELECT * FROM empdb.jspdata"; + Statement stmt = con.createStatement(); + ResultSet rs = stmt.executeQuery(qry); + while (rs.next()) { + cus = new Customer(); + id = rs.getString(1); + cus.setId(id); + name = rs.getString(2); + cus.setName(name); + email = rs.getString(3); + cus.setEmail(email); + phone = rs.getString(4); + cus.setPhone(phone); + cus=buildUser(name, id, email, phone); + list.add(cus); + } + con.close(); + return list; + } + public Customer buildUser(String name,String id,String email,String phone){ + Customer cus; + cus=new Customer(); + cus.setName(name); + cus.setId(id); + cus.setEmail(email); + cus.setPhone(phone); + return cus; + + } +} diff --git a/JspDemo/.classpath b/JspDemo/.classpath new file mode 100644 index 0000000..ad7aec3 --- /dev/null +++ b/JspDemo/.classpath @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/JspDemo/.project b/JspDemo/.project new file mode 100644 index 0000000..7eee108 --- /dev/null +++ b/JspDemo/.project @@ -0,0 +1,36 @@ + + + JspDemo + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/JspDemo/.settings/.jsdtscope b/JspDemo/.settings/.jsdtscope new file mode 100644 index 0000000..92e666d --- /dev/null +++ b/JspDemo/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/JspDemo/.settings/org.eclipse.jdt.core.prefs b/JspDemo/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/JspDemo/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/JspDemo/.settings/org.eclipse.wst.common.component b/JspDemo/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..c2bc9d5 --- /dev/null +++ b/JspDemo/.settings/org.eclipse.wst.common.component @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/JspDemo/.settings/org.eclipse.wst.common.project.facet.core.xml b/JspDemo/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..2ccaeb9 --- /dev/null +++ b/JspDemo/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/JspDemo/.settings/org.eclipse.wst.jsdt.ui.superType.container b/JspDemo/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/JspDemo/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/JspDemo/.settings/org.eclipse.wst.jsdt.ui.superType.name b/JspDemo/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/JspDemo/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/JspDemo/WebContent/META-INF/MANIFEST.MF b/JspDemo/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/JspDemo/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/JspDemo/WebContent/WEB-INF/web.xml b/JspDemo/WebContent/WEB-INF/web.xml new file mode 100644 index 0000000..983ff4d --- /dev/null +++ b/JspDemo/WebContent/WEB-INF/web.xml @@ -0,0 +1,12 @@ + + + JspDemo + + index.html + index.htm + index.jsp + default.html + default.htm + default.jsp + + \ No newline at end of file diff --git a/JspDemo/WebContent/customerform.jsp b/JspDemo/WebContent/customerform.jsp new file mode 100644 index 0000000..03ede8a --- /dev/null +++ b/JspDemo/WebContent/customerform.jsp @@ -0,0 +1,39 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +customer jsp + + +

Register

+ + + + + + + + + + + + + + + + + + + +
ID : +
Name : +
Email : +
Phone : +
  +
+ + + + \ No newline at end of file diff --git a/JspDemo/WebContent/dataprint.jsp b/JspDemo/WebContent/dataprint.jsp new file mode 100644 index 0000000..792d3ca --- /dev/null +++ b/JspDemo/WebContent/dataprint.jsp @@ -0,0 +1,87 @@ +<%@page import="java.util.Map"%> +<%@page import="java.sql.*"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +dataprintjsp + + +

+Add new Customer

+

+

Customer list

+

+ <% +String url="jdbc:mysql://localhost:3306/empdb"; +String username="root"; +String passwd="root";%> + <% + try{ + Class.forName("com.mysql.jdbc.Driver"); + Connection con=DriverManager.getConnection(url,username,passwd); + //out.println("Connected Successfully........!"+"
"); + String qry = "SELECT * FROM empdb.jspdata"; + Statement st = con.createStatement(); + ResultSet rs = st.executeQuery(qry); + ResultSetMetaData rsmd = rs.getMetaData(); + int columnCount = rsmd.getColumnCount(); + %> + + + <% + for (int i = 1; i <= columnCount; i++) { + %> + + <% + } + %> + + + + <% + while (rs.next()) { + %> + + <% + for (int i = 1; i <= columnCount; i++) { + %> + + <% + } + %> + + + <% + } + %> +
<%=rsmd.getColumnLabel(i)%>edit/delete
<%=rs.getString(i)%> + + + + + +
+
+ +
+
+
+ +
+
+
+ + <% + con.close(); + } catch (Exception e) { + e.printStackTrace(); + } + %> + + + \ No newline at end of file diff --git a/JspDemo/WebContent/deleteuser.jsp b/JspDemo/WebContent/deleteuser.jsp new file mode 100644 index 0000000..296b8ed --- /dev/null +++ b/JspDemo/WebContent/deleteuser.jsp @@ -0,0 +1,130 @@ +<%@page import="java.io.IOException"%> +<%@page import="java.util.Map"%> +<%@page import="java.sql.*"%> +<%@page import="java.lang.Object"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +delete jsp + + +<% +Map parametermap=request.getParameterMap(); + String ID = parametermap.get("ID")[0].toString(); + System.out.println(ID); + %> + <% + try { + Connection con = null; + con = openConnection(); + handleDelete(out, ID, con); + out.print("
"+"Delete success"); + printAllUsersTable(out, con); + + + //printEditUserdetailsLink(out,rs); + + } catch (Exception e) { + e.printStackTrace(); + } + %> + <%! + private void handleDelete(JspWriter out, String ID, Connection con) throws SQLException, IOException { + ResultSet rs = loadUser(ID, con); + rs.next(); + + deleteUser(ID, con); + + printUserDeleteStatus(out, rs.getString(2), rs.getString(3), rs.getString(4)); + } + %> + <%! + private int deleteUser(String ID, Connection con) throws SQLException { + String qry = "Delete FROM empdb.jspdata where ID=?"; + PreparedStatement ps = con.prepareStatement(qry); + ps.setString(1, ID); + int deletedRowCount = ps.executeUpdate(); + return deletedRowCount; + } + %> + <%! + private ResultSet loadUser(String ID, Connection con) throws SQLException { + String qry = "SELECT * FROM empdb.jspdata where ID=?"; + PreparedStatement ps = con.prepareStatement(qry); + ps.setString(1, ID); + ResultSet rs = ps.executeQuery(); + return rs; + } + + + private Connection openConnection() throws ClassNotFoundException, SQLException { + Connection con; + Class.forName("com.mysql.jdbc.Driver"); + con = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb", "root", "root"); + System.out.println("connection success"); + return con; + } + + private void printUserDeleteStatus(JspWriter out, String Name, String Email, String Phone) throws IOException{ + out.append("

User Deleted success:

"); + out.append("
Name :" + Name); + out.append("    Email: " + Email); + out.append("    Phone :" + Phone); + } + + private ResultSet loadAllUsers(Connection con) throws SQLException { + String qry = "SELECT * FROM empdb.jspdata"; + Statement stmt = con.createStatement(); + ResultSet rs = stmt.executeQuery(qry); + return rs; + } + + + private void printAllUsersTable(JspWriter out, Connection con) throws SQLException,IOException { + ResultSet rs = loadAllUsers(con); + ResultSetMetaData rsmd = rs.getMetaData(); + int colCount = rsmd.getColumnCount(); + + out.append("

"); + out.append(""); + for (int i = 1; i <= colCount; i++) { + out.append(""); + } + out.append(""); + out.append(""); + out.append(""); + while (rs.next()) { + out.append(""); + String id = rs.getString(1); + for (int i = 1; i <= colCount; i++) { + out.append(""); + } + + createEditbutton(out, id); + + createDeletebutton(out, id); + + out.append(""); + } + out.print("
" + rsmd.getColumnLabel(i) + ""+"edit"+""+"delete"+"
" + rs.getString(i) + "

"); + } + + private void createDeletebutton(JspWriter out, String ID) throws IOException{ + out.println( + "" + "
" + "" + + "" + "
" + ""); + } + + + private void createEditbutton(JspWriter out, String ID) throws IOException{ + out.println("" + "
" + + "" + "" + + "
" + ""); + } + %> + + \ No newline at end of file diff --git a/JspDemo/WebContent/edituser.jsp b/JspDemo/WebContent/edituser.jsp new file mode 100644 index 0000000..7b510cc --- /dev/null +++ b/JspDemo/WebContent/edituser.jsp @@ -0,0 +1,71 @@ +<%@page import="java.util.Map"%> +<%@page import="java.sql.*"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +edit jsp + + +

Edit Your details

+<% +Map parameterMap = request.getParameterMap(); + String ID = parameterMap.get("ID")[0].toString(); + //out.println(ID); + try { + Connection con = null; + con = openConnection(); + + ResultSet rs = loadUser(ID, con); + + rs.next(); + + out.append("

Update User:

"); + out.append("
" ); + out.append("
" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "
Name: " + + "
Email: " + + "
Phone: " + + "
 " + + "" + + "" + + "" + + "
"); + + + //printEditUserdetailsLink(out,rs); + + } + catch (Exception e) { + e.printStackTrace(); + } + %> + <%! + private ResultSet loadUser(String ID,Connection con) throws SQLException { + String qry = "SELECT * FROM empdb.jspdata where ID=?"; + PreparedStatement ps = con.prepareStatement(qry); + ps.setString(1, ID); + ResultSet rs = ps.executeQuery(); + return rs; + } %> + <%! + private Connection openConnection() throws ClassNotFoundException, SQLException { + Connection con; + Class.forName("com.mysql.jdbc.Driver"); + con = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb", "root", "root"); + System.out.println("connection success"); + return con; + } %> + + + \ No newline at end of file diff --git a/JspDemo/WebContent/hello.jsp b/JspDemo/WebContent/hello.jsp new file mode 100644 index 0000000..f8d8ab0 --- /dev/null +++ b/JspDemo/WebContent/hello.jsp @@ -0,0 +1,16 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Welcome jsp + + +

Hello world

+Click here to register
+ +

+Click me to print..! + + \ No newline at end of file diff --git a/JspDemo/WebContent/index.html b/JspDemo/WebContent/index.html new file mode 100644 index 0000000..0942538 --- /dev/null +++ b/JspDemo/WebContent/index.html @@ -0,0 +1,18 @@ + + + + +Welcome page + + +

+

+ Welcome to ABBURI Solutions +

+

+

+ Click me..! +

+ + \ No newline at end of file diff --git a/JspDemo/WebContent/print.jsp b/JspDemo/WebContent/print.jsp new file mode 100644 index 0000000..2ad79bd --- /dev/null +++ b/JspDemo/WebContent/print.jsp @@ -0,0 +1,22 @@ +<%@page import="java.util.Map"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +print jsp + + +

Your details

+<% +Map parametermap=request.getParameterMap(); +String name=parametermap.get("name")[0].toString(); +String email=parametermap.get("email")[0].toString(); +String phone=parametermap.get("phone")[0].toString(); +%> +Name: <%=name%>
+Email: <%=email%>
+Phone: <%=phone%>
+ + \ No newline at end of file diff --git a/JspDemo/WebContent/saveuser.jsp b/JspDemo/WebContent/saveuser.jsp new file mode 100644 index 0000000..b622629 --- /dev/null +++ b/JspDemo/WebContent/saveuser.jsp @@ -0,0 +1,80 @@ +<%@page import="java.util.Map"%> +<%@page import="java.sql.*"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +database jsp + + +

Your + details

+ <% + Map parametermap = request.getParameterMap(); + String id = parametermap.get("id")[0].toString(); + String name = parametermap.get("name")[0].toString(); + String email = parametermap.get("email")[0].toString(); + String phone = parametermap.get("phone")[0].toString(); + %> + + + + + + + + + + + + + + + + + +
ID<%=id%>
Name<%=name%>
Email<%=email%>
Phone<%=phone%>
+ + <% + String url = "jdbc:mysql://localhost:3306/empdb"; + String username = "root"; + String passwd = "root"; + try { + Class.forName("com.mysql.jdbc.Driver"); + Connection con = DriverManager.getConnection(url, username, passwd); + String qry = "insert into jspdata(id,name,email,phone)values(?,?,?,?)"; + java.sql.PreparedStatement ps = con.prepareStatement(qry); + ps.setString(1, id); + ps.setString(2, name); + ps.setString(3, email); + ps.setString(4, phone); + int count = ps.executeUpdate(); + if (count > 0) { + %> +

+ Thank you for + registering...! + <% + } else { + %> + Try again... + <% + } + + } catch (SQLException e) { + e.printStackTrace(); + } catch (ClassNotFoundException ce) { + ce.printStackTrace(); + } + %> + + + + + +

+ + \ No newline at end of file diff --git a/JspDemo/WebContent/updateuser.jsp b/JspDemo/WebContent/updateuser.jsp new file mode 100644 index 0000000..50ca12b --- /dev/null +++ b/JspDemo/WebContent/updateuser.jsp @@ -0,0 +1,111 @@ +<%@page import="java.util.Map"%> +<%@page import="java.sql.*"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +edit jsp + + +

Edit Your details

+ <% + Map parametermap = request.getParameterMap(); + //String ID=parametermap.get("ID")[0].toString(); + String ID = parametermap.get("ID")[0].toString(); + String Name = parametermap.get("name")[0].toString(); + String Email = parametermap.get("email")[0].toString(); + String Phone = parametermap.get("phone")[0].toString(); + out.println(ID); + out.println(Name); + out.println(Email); + out.println(Phone); + + try { + Connection con = null; + con = openConnection(); + updateUser(ID, Name, Email, Phone, con); + out.append("
" + " update success"); + String qry = "SELECT * FROM empdb.jspdata"; + Statement st = con.createStatement(); + ResultSet rs = st.executeQuery(qry); + + ResultSetMetaData rsmd = rs.getMetaData(); + int columnCount = rsmd.getColumnCount(); + // table header + %> + + + <% + for (int i = 1; i <= columnCount; i++) { + %> + + <% + } + %> + + + + <% + while (rs.next()) { + %> + + <% + for (int i = 1; i <= columnCount; i++) { + %> + + <% + } + %> + + + <% + } + %> +
<%=rsmd.getColumnLabel(i)%>Edit/Delete
<%=rs.getString(i)%> + + + + + +
+
+ +
+
+
+ +
+
+
+ + <% + con.close(); + } catch (Exception e) { + e.printStackTrace(); + } + %> + + <%!private void updateUser(String ID, String Name, String Email, String Phone, Connection con) throws SQLException { + PreparedStatement ps; + String sql = "update empdb.jspdata set name = ?, email = ?, phone = ? where ID =" + ID + " "; + ps = con.prepareStatement(sql); + ps.setString(1, Name); + ps.setString(2, Email); + ps.setString(3, Phone); + ps.executeUpdate(); + System.out.println("user update!!!!!!!!!"); + } + + private Connection openConnection() throws ClassNotFoundException, SQLException { + Connection con; + Class.forName("com.mysql.jdbc.Driver"); + con = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb", "root", "root"); + System.out.println("connection success"); + return con; + }%> + + \ No newline at end of file diff --git a/JspDemo/WebContent/wallpaper.jpg b/JspDemo/WebContent/wallpaper.jpg new file mode 100644 index 0000000..fe33c72 Binary files /dev/null and b/JspDemo/WebContent/wallpaper.jpg differ diff --git a/JspSendRedirectDemo/.classpath b/JspSendRedirectDemo/.classpath new file mode 100644 index 0000000..ad7aec3 --- /dev/null +++ b/JspSendRedirectDemo/.classpath @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/JspSendRedirectDemo/.project b/JspSendRedirectDemo/.project new file mode 100644 index 0000000..d815609 --- /dev/null +++ b/JspSendRedirectDemo/.project @@ -0,0 +1,36 @@ + + + JspSendRedirectDemo + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/JspSendRedirectDemo/.settings/.jsdtscope b/JspSendRedirectDemo/.settings/.jsdtscope new file mode 100644 index 0000000..92e666d --- /dev/null +++ b/JspSendRedirectDemo/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/JspSendRedirectDemo/.settings/org.eclipse.jdt.core.prefs b/JspSendRedirectDemo/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/JspSendRedirectDemo/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/JspSendRedirectDemo/.settings/org.eclipse.wst.common.component b/JspSendRedirectDemo/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..54ef661 --- /dev/null +++ b/JspSendRedirectDemo/.settings/org.eclipse.wst.common.component @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/JspSendRedirectDemo/.settings/org.eclipse.wst.common.project.facet.core.xml b/JspSendRedirectDemo/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..7d72b07 --- /dev/null +++ b/JspSendRedirectDemo/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/JspSendRedirectDemo/.settings/org.eclipse.wst.jsdt.ui.superType.container b/JspSendRedirectDemo/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/JspSendRedirectDemo/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/JspSendRedirectDemo/.settings/org.eclipse.wst.jsdt.ui.superType.name b/JspSendRedirectDemo/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/JspSendRedirectDemo/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/JspSendRedirectDemo/WebContent/Business.jpg b/JspSendRedirectDemo/WebContent/Business.jpg new file mode 100644 index 0000000..19ec2df Binary files /dev/null and b/JspSendRedirectDemo/WebContent/Business.jpg differ diff --git a/JspSendRedirectDemo/WebContent/META-INF/MANIFEST.MF b/JspSendRedirectDemo/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/JspSendRedirectDemo/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/JspSendRedirectDemo/WebContent/Neg.jpg b/JspSendRedirectDemo/WebContent/Neg.jpg new file mode 100644 index 0000000..0fb837d Binary files /dev/null and b/JspSendRedirectDemo/WebContent/Neg.jpg differ diff --git a/JspSendRedirectDemo/WebContent/WEB-INF/web.xml b/JspSendRedirectDemo/WebContent/WEB-INF/web.xml new file mode 100644 index 0000000..537da6e --- /dev/null +++ b/JspSendRedirectDemo/WebContent/WEB-INF/web.xml @@ -0,0 +1,12 @@ + + + JspSendRedirectDemo + + index.html + index.htm + index.jsp + default.html + default.htm + default.jsp + + \ No newline at end of file diff --git a/JspSendRedirectDemo/WebContent/customerform.jsp b/JspSendRedirectDemo/WebContent/customerform.jsp new file mode 100644 index 0000000..d6d4df3 --- /dev/null +++ b/JspSendRedirectDemo/WebContent/customerform.jsp @@ -0,0 +1,39 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +customer jsp + + +

Register

+
+ + + + + + + + + + + + + + + + + + +
ID : +
Name : +
Email : +
Phone : +
  +
+ +
+ + \ No newline at end of file diff --git a/JspSendRedirectDemo/WebContent/dataprint.jsp b/JspSendRedirectDemo/WebContent/dataprint.jsp new file mode 100644 index 0000000..44e84c1 --- /dev/null +++ b/JspSendRedirectDemo/WebContent/dataprint.jsp @@ -0,0 +1,99 @@ +<%@page import="java.util.Map"%> +<%@page import="java.sql.*"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +dataprintjsp + + +

+Add new Customer

+

+

Customer list

+

+ <% + + Map parametermap = request.getParameterMap(); + String Name = parametermap.get("name")[0].toString(); + String Email = parametermap.get("email")[0].toString(); + String Phone = parametermap.get("phone")[0].toString(); + %> +

Update Success

+

Name: <%=Name%>

+

Email: <%=Email%>

+

Phone: <%=Phone%>

+<% +String url="jdbc:mysql://localhost:3306/empdb"; +String username="root"; +String passwd="root"; +%> + <% + try{ + Class.forName("com.mysql.jdbc.Driver"); + Connection con=DriverManager.getConnection(url,username,passwd); + //out.println("Connected Successfully........!"+"
"); + String qry = "SELECT * FROM empdb.jspdata"; + Statement st = con.createStatement(); + ResultSet rs = st.executeQuery(qry); + ResultSetMetaData rsmd = rs.getMetaData(); + int columnCount = rsmd.getColumnCount(); + %> + + + <% + for (int i = 1; i <= columnCount; i++) { + %> + + <% + } + %> + + + + <% + while (rs.next()) { + %> + + <% + for (int i = 1; i <= columnCount; i++) { + %> + + <% + } + %> + + + <% + } + %> +
<%=rsmd.getColumnLabel(i)%>edit/delete
<%=rs.getString(i)%> + + + + + +
+
+ +
+
+
+ +
+
+
+ + <% + con.close(); + } catch (Exception e) { + e.printStackTrace(); + } + %> + + + \ No newline at end of file diff --git a/JspSendRedirectDemo/WebContent/deleteuser.jsp b/JspSendRedirectDemo/WebContent/deleteuser.jsp new file mode 100644 index 0000000..b8588d9 --- /dev/null +++ b/JspSendRedirectDemo/WebContent/deleteuser.jsp @@ -0,0 +1,129 @@ +<%@page import="java.io.IOException"%> +<%@page import="java.util.Map"%> +<%@page import="java.sql.*"%> +<%@page import="java.lang.Object"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +delete jsp + + +<% +Map parametermap=request.getParameterMap(); + String ID = parametermap.get("ID")[0].toString(); + System.out.println(ID); + %> + <% + try { + Connection con = null; + con = openConnection(); + handleDelete(out, ID, con); + out.print("
"+"Delete success"); + printAllUsersTable(out, con); + + + //printEditUserdetailsLink(out,rs); + + } catch (Exception e) { + e.printStackTrace(); + } + %> + <%! + private void handleDelete(JspWriter out, String ID, Connection con) throws SQLException, IOException { + ResultSet rs = loadUser(ID, con); + rs.next(); + + deleteUser(ID, con); + + printUserDeleteStatus(out, rs.getString(2), rs.getString(3), rs.getString(4)); + } + + + private int deleteUser(String ID, Connection con) throws SQLException { + String qry = "Delete FROM empdb.jspdata where ID=?"; + PreparedStatement ps = con.prepareStatement(qry); + ps.setString(1, ID); + int deletedRowCount = ps.executeUpdate(); + return deletedRowCount; + } + + private ResultSet loadUser(String ID, Connection con) throws SQLException { + String qry = "SELECT * FROM empdb.jspdata where ID=?"; + PreparedStatement ps = con.prepareStatement(qry); + ps.setString(1, ID); + ResultSet rs = ps.executeQuery(); + return rs; + } + + + private Connection openConnection() throws ClassNotFoundException, SQLException { + Connection con; + Class.forName("com.mysql.jdbc.Driver"); + con = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb", "root", "root"); + System.out.println("connection success"); + return con; + } + + private void printUserDeleteStatus(JspWriter out, String Name, String Email, String Phone) throws IOException{ + out.append("

User Deleted success:

"); + out.append("
Name :" + Name); + out.append("    Email: " + Email); + out.append("    Phone :" + Phone); + } + + private ResultSet loadAllUsers(Connection con) throws SQLException { + String qry = "SELECT * FROM empdb.jspdata"; + Statement stmt = con.createStatement(); + ResultSet rs = stmt.executeQuery(qry); + return rs; + } + + + private void printAllUsersTable(JspWriter out, Connection con) throws SQLException,IOException { + ResultSet rs = loadAllUsers(con); + ResultSetMetaData rsmd = rs.getMetaData(); + int colCount = rsmd.getColumnCount(); + + out.append("

"); + out.append(""); + for (int i = 1; i <= colCount; i++) { + out.append(""); + } + out.append(""); + out.append(""); + out.append(""); + while (rs.next()) { + out.append(""); + String id = rs.getString(1); + for (int i = 1; i <= colCount; i++) { + out.append(""); + } + + createEditbutton(out, id); + + createDeletebutton(out, id); + + out.append(""); + } + out.print("
" + rsmd.getColumnLabel(i) + ""+"edit"+""+"delete"+"
" + rs.getString(i) + "

"); + } + + private void createDeletebutton(JspWriter out, String ID) throws IOException{ + out.println( + "" + "
" + "" + + "" + "
" + ""); + } + + + private void createEditbutton(JspWriter out, String ID) throws IOException{ + out.println("" + "
" + + "" + "" + + "
" + ""); + } + %> + + \ No newline at end of file diff --git a/JspSendRedirectDemo/WebContent/edituser.jsp b/JspSendRedirectDemo/WebContent/edituser.jsp new file mode 100644 index 0000000..a3823e8 --- /dev/null +++ b/JspSendRedirectDemo/WebContent/edituser.jsp @@ -0,0 +1,64 @@ +<%@page import="java.util.Map"%> +<%@page import="java.sql.*"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +edit jsp + + +<% +Map parameterMap = request.getParameterMap(); + String ID = parameterMap.get("ID")[0].toString(); + System.out.println(ID); + try { + Connection con = null; + con = openConnection(); + ResultSet rs = loadUser(ID, con); + rs.next(); + %> +

Update User:

+
+
+ + + + + + + + +
Name: +
Email: +
Phone: +
  + + + +
+ <% } + catch (Exception e) { + e.printStackTrace(); + } + %> + <%! + private ResultSet loadUser(String ID,Connection con) throws SQLException { + String qry = "SELECT * FROM empdb.jspdata where ID=?"; + PreparedStatement ps = con.prepareStatement(qry); + ps.setString(1, ID); + ResultSet rs = ps.executeQuery(); + return rs; + } + + private Connection openConnection() throws ClassNotFoundException, SQLException { + Connection con; + Class.forName("com.mysql.jdbc.Driver"); + con = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb", "root", "root"); + System.out.println("connection success"); + return con; + } + %> + + \ No newline at end of file diff --git a/JspSendRedirectDemo/WebContent/hello.jsp b/JspSendRedirectDemo/WebContent/hello.jsp new file mode 100644 index 0000000..e2927ae --- /dev/null +++ b/JspSendRedirectDemo/WebContent/hello.jsp @@ -0,0 +1,16 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Welcome jsp + + +

Hello world

+Click here to register
+ +

+ + + \ No newline at end of file diff --git a/JspSendRedirectDemo/WebContent/index.html b/JspSendRedirectDemo/WebContent/index.html new file mode 100644 index 0000000..9e0e91f --- /dev/null +++ b/JspSendRedirectDemo/WebContent/index.html @@ -0,0 +1,22 @@ + + + + +Welcome page + + +

+

+ Welcome to ABBURI Solutions +

+

+

+ Click me..! +

+
+ + +
+ + \ No newline at end of file diff --git a/JspSendRedirectDemo/WebContent/saveuser.jsp b/JspSendRedirectDemo/WebContent/saveuser.jsp new file mode 100644 index 0000000..b018835 --- /dev/null +++ b/JspSendRedirectDemo/WebContent/saveuser.jsp @@ -0,0 +1,83 @@ +<%@page import="java.util.Map"%> +<%@page import="java.sql.*"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +database jsp + + +

Your + details

+ <% + Map parametermap = request.getParameterMap(); + String id = parametermap.get("id")[0].toString(); + String name = parametermap.get("name")[0].toString(); + String email = parametermap.get("email")[0].toString(); + String phone = parametermap.get("phone")[0].toString(); + %> + + + + + + + + + + + + + + + + + +
ID<%=id%>
Name<%=name%>
Email<%=email%>
Phone<%=phone%>
+ + <% + String url = "jdbc:mysql://localhost:3306/empdb"; + String username = "root"; + String passwd = "root"; + try { + Class.forName("com.mysql.jdbc.Driver"); + Connection con = DriverManager.getConnection(url, username, passwd); + String qry = "insert into jspdata(id,name,email,phone)values(?,?,?,?)"; + java.sql.PreparedStatement ps = con.prepareStatement(qry); + ps.setString(1, id); + ps.setString(2, name); + ps.setString(3, email); + ps.setString(4, phone); + int count = ps.executeUpdate(); + if (count > 0) { + %> +

+ Thank you for + registering...! + <% + } else { + %> + Try again... + <% + } + + } catch (SQLException e) { + e.printStackTrace(); + } catch (ClassNotFoundException ce) { + ce.printStackTrace(); + } + %> +

+ + + + + + +

+

+ + \ No newline at end of file diff --git a/JspSendRedirectDemo/WebContent/updateuser.jsp b/JspSendRedirectDemo/WebContent/updateuser.jsp new file mode 100644 index 0000000..577fd6d --- /dev/null +++ b/JspSendRedirectDemo/WebContent/updateuser.jsp @@ -0,0 +1,70 @@ +<%@page import="java.util.Map"%> +<%@page import="java.sql.*"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +edit jsp + + +

Edit Your details

+ <% + Map parametermap = request.getParameterMap(); + String ID = parametermap.get("ID")[0].toString(); + String Name = parametermap.get("name")[0].toString(); + String Email = parametermap.get("email")[0].toString(); + String Phone = parametermap.get("phone")[0].toString(); + System.out.println(ID); + %> + +
+ + + + + +
+ + <% + try { + Connection con = null; + con = openConnection(); + updateUser(ID, Name, Email, Phone, con); + out.append("
" + "update success"); + String qry = "SELECT * FROM empdb.jspdata"; + Statement st = con.createStatement(); + ResultSet rs = st.executeQuery(qry); + + ResultSetMetaData rsmd = rs.getMetaData(); + int columnCount = rsmd.getColumnCount(); + // table header + + con.close(); + } catch (Exception e) { + e.printStackTrace(); + } + %> + + <%!private void updateUser(String ID, String Name, String Email, String Phone, Connection con) throws SQLException { + PreparedStatement ps; + String sql = "update empdb.jspdata set name = ?, email = ?, phone = ? where ID =" + ID + " "; + ps = con.prepareStatement(sql); + ps.setString(1, Name); + ps.setString(2, Email); + ps.setString(3, Phone); + ps.executeUpdate(); + System.out.println("user update!!!!!!!!!"); + } + + private Connection openConnection() throws ClassNotFoundException, SQLException { + Connection con; + Class.forName("com.mysql.jdbc.Driver"); + con = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb", "root", "root"); + System.out.println("connection success"); + return con; + }%> + + + \ No newline at end of file diff --git a/JspSendRedirectDemo/WebContent/wallpaper.jpg b/JspSendRedirectDemo/WebContent/wallpaper.jpg new file mode 100644 index 0000000..fe33c72 Binary files /dev/null and b/JspSendRedirectDemo/WebContent/wallpaper.jpg differ diff --git a/ServletDemo/.classpath b/ServletDemo/.classpath new file mode 100644 index 0000000..ad7aec3 --- /dev/null +++ b/ServletDemo/.classpath @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/ServletDemo/.project b/ServletDemo/.project new file mode 100644 index 0000000..c8ba166 --- /dev/null +++ b/ServletDemo/.project @@ -0,0 +1,36 @@ + + + ServletDemo + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/ServletDemo/.settings/.jsdtscope b/ServletDemo/.settings/.jsdtscope new file mode 100644 index 0000000..92e666d --- /dev/null +++ b/ServletDemo/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/ServletDemo/.settings/org.eclipse.jdt.core.prefs b/ServletDemo/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/ServletDemo/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/ServletDemo/.settings/org.eclipse.wst.common.component b/ServletDemo/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..c01d868 --- /dev/null +++ b/ServletDemo/.settings/org.eclipse.wst.common.component @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/ServletDemo/.settings/org.eclipse.wst.common.project.facet.core.xml b/ServletDemo/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..2ccaeb9 --- /dev/null +++ b/ServletDemo/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/ServletDemo/.settings/org.eclipse.wst.jsdt.ui.superType.container b/ServletDemo/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/ServletDemo/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/ServletDemo/.settings/org.eclipse.wst.jsdt.ui.superType.name b/ServletDemo/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/ServletDemo/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/ServletDemo/WebContent/META-INF/MANIFEST.MF b/ServletDemo/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/ServletDemo/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/ServletDemo/WebContent/WEB-INF/web.xml b/ServletDemo/WebContent/WEB-INF/web.xml new file mode 100644 index 0000000..6908543 --- /dev/null +++ b/ServletDemo/WebContent/WEB-INF/web.xml @@ -0,0 +1,12 @@ + + + ServletDemo + + index.html + index.htm + index.jsp + default.html + default.htm + default.jsp + + \ No newline at end of file diff --git a/ServletDemo/WebContent/datainsert.html b/ServletDemo/WebContent/datainsert.html new file mode 100644 index 0000000..ec8099b --- /dev/null +++ b/ServletDemo/WebContent/datainsert.html @@ -0,0 +1,33 @@ + + + + +Registration Page + + +

Add

+
+
+ + + + + + + + + + + + + + + +
Name : +
Email : +
Phone : +
  +
+
+ + \ No newline at end of file diff --git a/ServletDemo/WebContent/index.html b/ServletDemo/WebContent/index.html new file mode 100644 index 0000000..da20617 --- /dev/null +++ b/ServletDemo/WebContent/index.html @@ -0,0 +1,14 @@ + + + + +Welcome page + + +

Welcome

+
+Click here to register +
+Click here to print + + \ No newline at end of file diff --git a/ServletDemo/WebContent/print.html b/ServletDemo/WebContent/print.html new file mode 100644 index 0000000..e789f1a --- /dev/null +++ b/ServletDemo/WebContent/print.html @@ -0,0 +1,14 @@ + + + + +Printing Page + + +

click print

+
+
+ +
+ + \ No newline at end of file diff --git a/ServletDemo/WebContent/test.html b/ServletDemo/WebContent/test.html new file mode 100644 index 0000000..4aec435 --- /dev/null +++ b/ServletDemo/WebContent/test.html @@ -0,0 +1,12 @@ + + + + +Insert title here + + +
+ +
+ + \ No newline at end of file diff --git a/ServletDemo/build/classes/DataInsertionServlet.class b/ServletDemo/build/classes/DataInsertionServlet.class new file mode 100644 index 0000000..ef3cae6 Binary files /dev/null and b/ServletDemo/build/classes/DataInsertionServlet.class differ diff --git a/ServletDemo/build/classes/DataPrint.class b/ServletDemo/build/classes/DataPrint.class new file mode 100644 index 0000000..017e494 Binary files /dev/null and b/ServletDemo/build/classes/DataPrint.class differ diff --git a/ServletDemo/build/classes/DeleteUser.class b/ServletDemo/build/classes/DeleteUser.class new file mode 100644 index 0000000..80f4f96 Binary files /dev/null and b/ServletDemo/build/classes/DeleteUser.class differ diff --git a/ServletDemo/build/classes/EditUser.class b/ServletDemo/build/classes/EditUser.class new file mode 100644 index 0000000..be6e60b Binary files /dev/null and b/ServletDemo/build/classes/EditUser.class differ diff --git a/ServletDemo/build/classes/HTTPRequestHeadersDemo.class b/ServletDemo/build/classes/HTTPRequestHeadersDemo.class new file mode 100644 index 0000000..0a82785 Binary files /dev/null and b/ServletDemo/build/classes/HTTPRequestHeadersDemo.class differ diff --git a/ServletDemo/build/classes/LargeServletPage.class b/ServletDemo/build/classes/LargeServletPage.class new file mode 100644 index 0000000..76a0d2a Binary files /dev/null and b/ServletDemo/build/classes/LargeServletPage.class differ diff --git a/ServletDemo/build/classes/UpdateUser.class b/ServletDemo/build/classes/UpdateUser.class new file mode 100644 index 0000000..0759451 Binary files /dev/null and b/ServletDemo/build/classes/UpdateUser.class differ diff --git a/ServletDemo/src/DataInsertionServlet.java b/ServletDemo/src/DataInsertionServlet.java new file mode 100644 index 0000000..d6d5f9e --- /dev/null +++ b/ServletDemo/src/DataInsertionServlet.java @@ -0,0 +1,84 @@ +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Map; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Servlet implementation class DataInsertionServlet + */ +@WebServlet("/DataInsertionServlet") +public class DataInsertionServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + /** + * @see HttpServlet#HttpServlet() + */ + public DataInsertionServlet() { + super(); + // TODO Auto-generated constructor stub + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String name; + String email; + String phone; + String url="jdbc:mysql://localhost:3306/empdb"; + String username="root"; + String passwd="root"; + response.setContentType("text/html"); + PrintWriter out=response.getWriter(); + Map parametermap=request.getParameterMap(); + name=parametermap.get("name")[0].toString(); + email=parametermap.get("email")[0].toString(); + phone=parametermap.get("phone")[0].toString(); + /*name=request.getParameter("name"); + email=request.getParameter("email"); + phone=request.getParameter("phone");*/ + out.println("

Name:"+name+"

"); + out.println("

Email:"+email+"

"); + out.println("

Phone:"+phone+"

"); + try{ + Class.forName("com.mysql.jdbc.Driver"); + Connection con=DriverManager.getConnection(url,username,passwd); + //out.println("Connected Successfully........!"+"
"); + String qry = "insert into userdata(name,email,phone)values(?,?,?)"; + java.sql.PreparedStatement ps=con.prepareStatement(qry); + ps.setString(1, name); + ps.setString(2, email); + ps.setString(3, phone); + int count=ps.executeUpdate(); + if(count>0){ + out.println("

Thank you for registering with us...!

"); + } + else + { + out.println("Try again..."); + } + + } + catch(SQLException | ClassNotFoundException e){ + e.printStackTrace(); + } + + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + doGet(request, response); + } + +} diff --git a/ServletDemo/src/DataPrint.java b/ServletDemo/src/DataPrint.java new file mode 100644 index 0000000..d020703 --- /dev/null +++ b/ServletDemo/src/DataPrint.java @@ -0,0 +1,97 @@ + + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Servlet implementation class DataPrint + */ +@WebServlet("/DataPrint") +public class DataPrint extends HttpServlet { + private static final long serialVersionUID = 1L; + + /** + * @see HttpServlet#HttpServlet() + */ + public DataPrint() { + super(); + // TODO Auto-generated constructor stub + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + String url="jdbc:mysql://localhost:3306/empdb"; + String username="root"; + String passwd="root"; + response.setContentType("text/html"); + PrintWriter out=response.getWriter(); + try{ + Class.forName("com.mysql.jdbc.Driver"); + Connection con=DriverManager.getConnection(url,username,passwd); + out.println("Connected Successfully........!"); + + String qry = "SELECT * FROM empdb.userdata"; + Statement st = con.createStatement(); + ResultSet rs = st.executeQuery(qry); + out.println("

"); + ResultSetMetaData rsmd = rs.getMetaData(); + int columnCount = rsmd.getColumnCount(); + // table header + out.println(""); + for (int i = 1; i <=columnCount; i++) { + out.println(""); + + out.println(""); + // the data + while (rs.next()) { + out.println(""); + for (int i = 1; i <=columnCount; i++) { + out.println(""); + } + out.println(""); + out.println(""); + } + out.println("
" + rsmd.getColumnLabel(i)); + } + out.println("Edit/Delete
" + rs.getString(i) + ""); + out.println("
" + +"" + +"" + +"
"); + out.println("
" + +"" + +"" + +"
"); + out.println("

"); + con.close(); + } + catch(SQLException | ClassNotFoundException e){ + e.printStackTrace(); + } + + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + doGet(request, response); + } + +} diff --git a/ServletDemo/src/DeleteUser.java b/ServletDemo/src/DeleteUser.java new file mode 100644 index 0000000..01875ce --- /dev/null +++ b/ServletDemo/src/DeleteUser.java @@ -0,0 +1,150 @@ + + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Map; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Servlet implementation class EditUser + */ +@WebServlet("/DeleteUser") +public class DeleteUser extends HttpServlet { + private static final long serialVersionUID = 1L; + + /** + * @see HttpServlet#HttpServlet() + */ + public DeleteUser() { + super(); + // TODO Auto-generated constructor stub + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + response.setContentType("text/html"); + PrintWriter out= response.getWriter(); + out.println("DeleteUser"); + Map parametermap=request.getParameterMap(); + String ID = parametermap.get("ID")[0].toString(); + System.out.println(ID); + try { + Connection con = null; + con = openConnection(); + handleDelete(out, ID, con); + out.print("
"+"Delete success"); + printAllUsersTable(out, con); + + + //printEditUserdetailsLink(out,rs); + + } catch (Exception e) { + e.printStackTrace(); + } + } + private void handleDelete(PrintWriter out, String ID, Connection con) throws SQLException { + ResultSet rs = loadUser(ID, con); + rs.next(); + + deleteUser(ID, con); + + printUserDeleteStatus(out, rs.getString(2), rs.getString(3), rs.getString(4)); + } + + private int deleteUser(String ID, Connection con) throws SQLException { + String qry = "Delete FROM empdb.userdata where ID=?"; + PreparedStatement ps = con.prepareStatement(qry); + ps.setString(1, ID); + int deletedRowCount = ps.executeUpdate(); + return deletedRowCount; + } + + private ResultSet loadUser(String ID, Connection con) throws SQLException { + String qry = "SELECT * FROM empdb.userdata where ID=?"; + PreparedStatement ps = con.prepareStatement(qry); + ps.setString(1, ID); + ResultSet rs = ps.executeQuery(); + return rs; + } + private Connection openConnection() throws ClassNotFoundException, SQLException { + Connection con; + Class.forName("com.mysql.jdbc.Driver"); + con = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb", "root", "root"); + System.out.println("connection success"); + return con; + } + private void printUserDeleteStatus(PrintWriter out, String Name, String Email, String Phone) { + out.append("

User Deleted success:

"); + out.append("
Name :" + Name); + out.append("    Email: " + Email); + out.append("    Phone :" + Phone); + } + private ResultSet loadAllUsers(Connection con) throws SQLException { + String qry = "SELECT * FROM empdb.userdata"; + Statement stmt = con.createStatement(); + ResultSet rs = stmt.executeQuery(qry); + return rs; + } + + private void printAllUsersTable(PrintWriter out, Connection con) throws SQLException { + ResultSet rs = loadAllUsers(con); + ResultSetMetaData rsmd = rs.getMetaData(); + int colCount = rsmd.getColumnCount(); + + out.append("

"); + out.append(""); + for (int i = 0; i < colCount; i++) { + out.append(""); + } + out.append(""); + while (rs.next()) { + out.append(""); + String userName = rs.getString(1); + for (int i = 1; i <= colCount; i++) { + out.append(""); + } + + createEditbutton(out, userName); + createDeletebutton(out, userName); + + out.append(""); + } + out.print("
" + rsmd.getColumnLabel(i + 1) + "
" + rs.getString(i) + "

"); + } + private void createDeletebutton(PrintWriter out, String ID) { + out.append( + "" + "
" + "" + + "" + "
" + ""); + } + + private void createEditbutton(PrintWriter out, String ID) { + out.append("" + "
" + + "" + "" + + "
" + ""); + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + doGet(request, response); + } + +} diff --git a/ServletDemo/src/EditUser.java b/ServletDemo/src/EditUser.java new file mode 100644 index 0000000..66c9c49 --- /dev/null +++ b/ServletDemo/src/EditUser.java @@ -0,0 +1,109 @@ + + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Map; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +/** + * Servlet implementation class EditUser + */ +@WebServlet("/EditUser") +public class EditUser extends HttpServlet { + private static final long serialVersionUID = 1L; + + /** + * @see HttpServlet#HttpServlet() + */ + public EditUser() { + super(); + // TODO Auto-generated constructor stub + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + out.println("Edit user"); + Map parameterMap = request.getParameterMap(); + String ID = parameterMap.get("ID")[0].toString(); + //out.println(ID); + try { + Connection con = null; + con = openConnection(); + + ResultSet rs = loadUser(ID, con); + + rs.next(); + + out.append("

Update User:

"); + out.append("
" ); + out.append("
" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "
Name: " + + "
Email: " + + "
Phone: " + + "
 " + + "" + + "" + /*+ "" + + "" + + ""*/ + + "" + + "
"); + + + //printEditUserdetailsLink(out,rs); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + private ResultSet loadUser(String ID,Connection con) throws SQLException { + String qry = "SELECT * FROM empdb.userdata where ID=?"; + PreparedStatement ps = con.prepareStatement(qry); + ps.setString(1, ID); + ResultSet rs = ps.executeQuery(); + return rs; + } + private Connection openConnection() throws ClassNotFoundException, SQLException { + Connection con; + Class.forName("com.mysql.jdbc.Driver"); + con = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb", "root", "root"); + System.out.println("connection success"); + return con; + } + + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + doGet(request, response); + } + +} diff --git a/ServletDemo/src/HTTPRequestHeadersDemo.java b/ServletDemo/src/HTTPRequestHeadersDemo.java new file mode 100644 index 0000000..fcba3ba --- /dev/null +++ b/ServletDemo/src/HTTPRequestHeadersDemo.java @@ -0,0 +1,59 @@ + + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Servlet implementation class HTTPRequestHeadersDemo + */ +@WebServlet("/HTTPRequestHeadersDemo") +public class HTTPRequestHeadersDemo extends HttpServlet { + private static final long serialVersionUID = 1L; + + /** + * @see HttpServlet#HttpServlet() + */ + public HTTPRequestHeadersDemo() { + super(); + // TODO Auto-generated constructor stub + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + response.getWriter().append("Served at: " ).append(request.getContextPath()); + response.setContentType("text/html"); + PrintWriter out=response.getWriter(); + out.println(""+"show all headers"); + out.println("

Showing All Request Headers

"); + out.println("

Request Method:"+request.getMethod()); + out.println("

Request URI:"+request.getRequestURI()); + out.println("

Request protocol:"+request.getProtocol()); + Enumeration headerNames=request.getHeaderNames(); + while(headerNames.hasMoreElements()){ + String headerName =headerNames.nextElement(); + out.println("

"+headerName+":"+request.getHeader(headerName)+"

"); + } + out.println(""); + out.println(""); + out.close(); + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + doGet(request, response); + } + +} diff --git a/ServletDemo/src/LargeServletPage.java b/ServletDemo/src/LargeServletPage.java new file mode 100644 index 0000000..8187ceb --- /dev/null +++ b/ServletDemo/src/LargeServletPage.java @@ -0,0 +1,59 @@ + + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * Servlet implementation class LargeServletPage + */ +@WebServlet("/LargeServletPage") +public class LargeServletPage extends HttpServlet { + private static final long serialVersionUID = 1L; + + /** + * @see HttpServlet#HttpServlet() + */ + public LargeServletPage() { + super(); + // TODO Auto-generated constructor stub + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + //response.getWriter().append("Served at: ").append(request.getContextPath()); + response.setContentType("text/html"); + PrintWriter out=response.getWriter(); + String dummyLine="To avoid the user account to be lockout from the operating system, DSM " + + "turns on the Invalid Credentials internal flag and stop trying to connect " + + "to the monitored database, until the Invalid " + + "Credentials flag is turned off."; + out.println(""+"show all headers"); + out.println("

Large Servlet Page

"); + for(int i=0;i<10000;i++) + { + out.println(dummyLine+"
"); + } + out.println(""); + out.println(""); + out.close(); + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + doGet(request, response); + } + +} diff --git a/ServletDemo/src/UpdateUser.java b/ServletDemo/src/UpdateUser.java new file mode 100644 index 0000000..b09cf82 --- /dev/null +++ b/ServletDemo/src/UpdateUser.java @@ -0,0 +1,130 @@ + + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +/** + * Servlet implementation class UpdateUser + */ +@WebServlet("/UpdateUser") +public class UpdateUser extends HttpServlet { + private static final long serialVersionUID = 1L; + + /** + * @see HttpServlet#HttpServlet() + */ + public UpdateUser() { + super(); + // TODO Auto-generated constructor stub + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + response.setContentType("text/html"); + PrintWriter out=response.getWriter(); + Connection con = null; + out.println("UPDATE USER"); + java.util.Map parametermap= request.getParameterMap(); + //String ID=parametermap.get("ID")[0].toString(); + String ID=parametermap.get("ID")[0].toString(); + String Name=parametermap.get("Name")[0].toString(); + String Email=parametermap.get("Email")[0].toString(); + String Phone=parametermap.get("Phone")[0].toString(); + out.println(ID); + out.println(Email); + out.println(Phone); + + try { + + con = openConnection(); + //String sql="UPDATE EMPDB.USERDATA WHERE ID="+ ID +" "; + //System.out.println(ID); + updateUser(ID,Name,Email,Phone,con); + out.append("
"+" update success"); + String qry = "SELECT * FROM empdb.userdata"; + Statement st = con.createStatement(); + ResultSet rs = st.executeQuery(qry); + out.append("

"); + ResultSetMetaData rsmd = rs.getMetaData(); + int columnCount = rsmd.getColumnCount(); + // table header + out.println(""); + for (int i = 1; i <=columnCount; i++) { + out.append(""); + + out.println(""); + // the data + while (rs.next()) { + out.println(""); + for (int i = 1; i <=columnCount; i++) { + out.println(""); + } + out.append(""); + out.println(""); + } + out.println("
" + rsmd.getColumnLabel(i)); + } + out.println("Edit/Delete
" + rs.getString(i) + ""); + out.print("" + +"" + +"" + +""); + out.print("
" + +"" + +"" + +"
"); + out.println("

"); + con.close(); + + } + catch (Exception e) { + e.printStackTrace(); + } + } + private void updateUser(String ID, String name,String email,String phone,Connection con) + throws SQLException { + PreparedStatement ps; + String sql = "update empdb.userdata set name = ?, email = ?, phone = ? where ID ="+ ID +" "; + ps = con.prepareStatement(sql); + ps.setString(1, name); + ps.setString(2, email); + ps.setString(3, phone); + ps.executeUpdate(); + System.out.println("user update!!!!!!!!!"); + } + + private Connection openConnection() throws ClassNotFoundException, SQLException { + Connection con; + Class.forName("com.mysql.jdbc.Driver"); + con = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb", "root", "root"); + System.out.println("connection success"); + return con; + } + + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + doGet(request, response); + } + +} diff --git a/SpringMvcJdbcTemplate/.classpath b/SpringMvcJdbcTemplate/.classpath new file mode 100644 index 0000000..5535224 --- /dev/null +++ b/SpringMvcJdbcTemplate/.classpath @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SpringMvcJdbcTemplate/.project b/SpringMvcJdbcTemplate/.project new file mode 100644 index 0000000..487a748 --- /dev/null +++ b/SpringMvcJdbcTemplate/.project @@ -0,0 +1,48 @@ + + + SpringMvcJdbcTemplate + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + org.springframework.ide.eclipse.core.springbuilder + + + + + + org.springframework.ide.eclipse.core.springnature + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/SpringMvcJdbcTemplate/.settings/.jsdtscope b/SpringMvcJdbcTemplate/.settings/.jsdtscope new file mode 100644 index 0000000..b46b920 --- /dev/null +++ b/SpringMvcJdbcTemplate/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/SpringMvcJdbcTemplate/.settings/org.eclipse.jdt.core.prefs b/SpringMvcJdbcTemplate/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..6249222 --- /dev/null +++ b/SpringMvcJdbcTemplate/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/SpringMvcJdbcTemplate/.settings/org.eclipse.m2e.core.prefs b/SpringMvcJdbcTemplate/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..b8a0537 --- /dev/null +++ b/SpringMvcJdbcTemplate/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,5 @@ +#Mon Jun 18 13:11:23 MDT 2012 +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/SpringMvcJdbcTemplate/.settings/org.eclipse.wst.common.component b/SpringMvcJdbcTemplate/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..48f97d3 --- /dev/null +++ b/SpringMvcJdbcTemplate/.settings/org.eclipse.wst.common.component @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/SpringMvcJdbcTemplate/.settings/org.eclipse.wst.common.project.facet.core.xml b/SpringMvcJdbcTemplate/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..62ee0c6 --- /dev/null +++ b/SpringMvcJdbcTemplate/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/SpringMvcJdbcTemplate/.settings/org.eclipse.wst.jsdt.ui.superType.container b/SpringMvcJdbcTemplate/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/SpringMvcJdbcTemplate/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/SpringMvcJdbcTemplate/.settings/org.eclipse.wst.jsdt.ui.superType.name b/SpringMvcJdbcTemplate/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/SpringMvcJdbcTemplate/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/SpringMvcJdbcTemplate/.settings/org.eclipse.wst.validation.prefs b/SpringMvcJdbcTemplate/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..04cad8c --- /dev/null +++ b/SpringMvcJdbcTemplate/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/SpringMvcJdbcTemplate/pom.xml b/SpringMvcJdbcTemplate/pom.xml new file mode 100644 index 0000000..f54e7c5 --- /dev/null +++ b/SpringMvcJdbcTemplate/pom.xml @@ -0,0 +1,84 @@ + + + 4.0.0 + + net.codejava.spring + SpringMvcJdbcTemplate + 1.0 + war + + SpringMvcJdbcTemplate + http://maven.apache.org + + + 1.7 + 4.0.3.RELEASE + 2.2.2 + + + + + + org.springframework + spring-context + ${spring.version} + + + + org.springframework + spring-webmvc + ${spring.version} + + + org.springframework + spring-orm + ${spring.version} + jar + compile + + + + + cglib + cglib-nodep + ${cglib.version} + runtime + + + + + + javax.servlet + javax.servlet-api + 3.1.0 + provided + + + javax.servlet.jsp + javax.servlet.jsp-api + 2.3.1 + provided + + + jstl + jstl + 1.2 + + + + + + SpringMvcJdbcTemplate + + + org.apache.maven.plugins + maven-compiler-plugin + 2.0.2 + + ${java.version} + ${java.version} + + + + + diff --git a/SpringMvcJdbcTemplate/sql/MySQL_script.sql b/SpringMvcJdbcTemplate/sql/MySQL_script.sql new file mode 100644 index 0000000..afb943d --- /dev/null +++ b/SpringMvcJdbcTemplate/sql/MySQL_script.sql @@ -0,0 +1,10 @@ +create database contactdb; + +CREATE TABLE `contact` ( + `contact_id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(45) NOT NULL, + `email` varchar(45) NOT NULL, + `address` varchar(45) NOT NULL, + `telephone` varchar(45) NOT NULL, + PRIMARY KEY (`contact_id`) +) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8 \ No newline at end of file diff --git a/SpringMvcJdbcTemplate/src/main/java/net/codejava/spring/config/MvcConfiguration.java b/SpringMvcJdbcTemplate/src/main/java/net/codejava/spring/config/MvcConfiguration.java new file mode 100644 index 0000000..ef28b22 --- /dev/null +++ b/SpringMvcJdbcTemplate/src/main/java/net/codejava/spring/config/MvcConfiguration.java @@ -0,0 +1,51 @@ +package net.codejava.spring.config; + +import javax.sql.DataSource; + +import net.codejava.spring.dao.ContactDAO; +import net.codejava.spring.dao.ContactDAOImpl; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.web.servlet.ViewResolver; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.view.InternalResourceViewResolver; + +@Configuration +@ComponentScan(basePackages="net.codejava.spring") +@EnableWebMvc +public class MvcConfiguration extends WebMvcConfigurerAdapter{ + + @Bean + public ViewResolver getViewResolver(){ + InternalResourceViewResolver resolver = new InternalResourceViewResolver(); + resolver.setPrefix("/"); + resolver.setSuffix(".jsp"); + return resolver; + } + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); + } + + @Bean + public DataSource getDataSource() { + DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName("com.mysql.jdbc.Driver"); + dataSource.setUrl("jdbc:mysql://localhost:3306/empdb"); + dataSource.setUsername("root"); + dataSource.setPassword("root"); + + return dataSource; + } + + @Bean + public ContactDAO getContactDAO() { + return new ContactDAOImpl(getDataSource()); + } +} diff --git a/SpringMvcJdbcTemplate/src/main/java/net/codejava/spring/controller/HomeController.java b/SpringMvcJdbcTemplate/src/main/java/net/codejava/spring/controller/HomeController.java new file mode 100644 index 0000000..562de22 --- /dev/null +++ b/SpringMvcJdbcTemplate/src/main/java/net/codejava/spring/controller/HomeController.java @@ -0,0 +1,69 @@ +package net.codejava.spring.controller; + +import java.io.IOException; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import net.codejava.spring.dao.ContactDAO; +import net.codejava.spring.model.Contact; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +/** + * This controller routes accesses to the application to the appropriate + * hanlder methods. + * @author www.codejava.net + * + */ +@Controller +public class HomeController { + + @Autowired + private ContactDAO contactDAO; + + @RequestMapping(value="/list") + public ModelAndView listContact(ModelAndView model) throws IOException{ + List listContact = contactDAO.list(); + model.addObject("listContact", listContact); + model.setViewName("home"); + + return model; + } + + @RequestMapping(value = "/newContact", method = RequestMethod.GET) + public ModelAndView newContact(ModelAndView model) { + Contact newContact = new Contact(); + model.addObject("contact", newContact); + model.setViewName("ContactForm"); + return model; + } + + @RequestMapping(value = "/saveContact", method = RequestMethod.POST) + public ModelAndView saveContact(@ModelAttribute Contact contact) { + contactDAO.saveOrUpdate(contact); + return new ModelAndView("redirect:/list"); + } + + @RequestMapping(value = "/deleteContact", method = RequestMethod.GET) + public ModelAndView deleteContact(HttpServletRequest request) { + int contactId = Integer.parseInt(request.getParameter("id")); + contactDAO.delete(contactId); + return new ModelAndView("redirect:/list"); + } + + @RequestMapping(value = "/editContact", method = RequestMethod.GET) + public ModelAndView editContact(HttpServletRequest request) { + int contactId = Integer.parseInt(request.getParameter("id")); + Contact contact = contactDAO.get(contactId); + ModelAndView model = new ModelAndView("ContactForm"); + model.addObject("contact", contact); + + return model; + } +} diff --git a/SpringMvcJdbcTemplate/src/main/java/net/codejava/spring/dao/ContactDAO.java b/SpringMvcJdbcTemplate/src/main/java/net/codejava/spring/dao/ContactDAO.java new file mode 100644 index 0000000..8877060 --- /dev/null +++ b/SpringMvcJdbcTemplate/src/main/java/net/codejava/spring/dao/ContactDAO.java @@ -0,0 +1,21 @@ +package net.codejava.spring.dao; + +import java.util.List; + +import net.codejava.spring.model.Contact; + +/** + * Defines DAO operations for the contact model. + * @author www.codejava.net + * + */ +public interface ContactDAO { + + public void saveOrUpdate(Contact contact); + + public void delete(int contactId); + + public Contact get(int contactId); + + public List list(); +} diff --git a/SpringMvcJdbcTemplate/src/main/java/net/codejava/spring/dao/ContactDAOImpl.java b/SpringMvcJdbcTemplate/src/main/java/net/codejava/spring/dao/ContactDAOImpl.java new file mode 100644 index 0000000..271382e --- /dev/null +++ b/SpringMvcJdbcTemplate/src/main/java/net/codejava/spring/dao/ContactDAOImpl.java @@ -0,0 +1,100 @@ +package net.codejava.spring.dao; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +import javax.sql.DataSource; + +import net.codejava.spring.model.Contact; + +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.ResultSetExtractor; +import org.springframework.jdbc.core.RowMapper; + +/** + * An implementation of the ContactDAO interface. + * @author www.codejava.net + * + */ +public class ContactDAOImpl implements ContactDAO { + + private JdbcTemplate jdbcTemplate; + + public ContactDAOImpl(DataSource dataSource) { + jdbcTemplate = new JdbcTemplate(dataSource); + } + + @Override + public void saveOrUpdate(Contact contact) { + if (contact.getId() > 0) { + // update + String sql = "UPDATE contact SET name=?, email=?, address=?, " + + "telephone=? WHERE contact_id=?"; + jdbcTemplate.update(sql, contact.getName(), contact.getEmail(), + contact.getAddress(), contact.getTelephone(), contact.getId()); + } else { + // insert + String sql = "INSERT INTO contact (name, email, address, telephone)" + + " VALUES (?, ?, ?, ?)"; + jdbcTemplate.update(sql, contact.getName(), contact.getEmail(), + contact.getAddress(), contact.getTelephone()); + } + + } + + @Override + public void delete(int contactId) { + String sql = "DELETE FROM contact WHERE contact_id=?"; + jdbcTemplate.update(sql, contactId); + } + + @Override + public List list() { + String sql = "SELECT * FROM contact"; + List listContact = jdbcTemplate.query(sql, new RowMapper() { + + @Override + public Contact mapRow(ResultSet rs, int rowNum) throws SQLException { + Contact aContact = new Contact(); + + aContact.setId(rs.getInt("contact_id")); + aContact.setName(rs.getString("name")); + aContact.setEmail(rs.getString("email")); + aContact.setAddress(rs.getString("address")); + aContact.setTelephone(rs.getString("telephone")); + + return aContact; + } + + }); + + return listContact; + } + + @Override + public Contact get(int contactId) { + String sql = "SELECT * FROM contact WHERE contact_id=" + contactId; + return jdbcTemplate.query(sql, new ResultSetExtractor() { + + @Override + public Contact extractData(ResultSet rs) throws SQLException, + DataAccessException { + if (rs.next()) { + Contact contact = new Contact(); + contact.setId(rs.getInt("contact_id")); + contact.setName(rs.getString("name")); + contact.setEmail(rs.getString("email")); + contact.setAddress(rs.getString("address")); + contact.setTelephone(rs.getString("telephone")); + return contact; + } + + return null; + } + + }); + } + +} diff --git a/SpringMvcJdbcTemplate/src/main/java/net/codejava/spring/model/Contact.java b/SpringMvcJdbcTemplate/src/main/java/net/codejava/spring/model/Contact.java new file mode 100644 index 0000000..3fad395 --- /dev/null +++ b/SpringMvcJdbcTemplate/src/main/java/net/codejava/spring/model/Contact.java @@ -0,0 +1,60 @@ +package net.codejava.spring.model; + +public class Contact { + private int id; + private String name; + private String email; + private String address; + private String telephone; + + public Contact() { + } + + public Contact(String name, String email, String address, String telephone) { + this.name = name; + this.email = email; + this.address = address; + this.telephone = telephone; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getTelephone() { + return telephone; + } + + public void setTelephone(String telephone) { + this.telephone = telephone; + } + +} diff --git a/SpringMvcJdbcTemplate/src/main/webapp/ContactForm.jsp b/SpringMvcJdbcTemplate/src/main/webapp/ContactForm.jsp new file mode 100644 index 0000000..5f2547f --- /dev/null +++ b/SpringMvcJdbcTemplate/src/main/webapp/ContactForm.jsp @@ -0,0 +1,40 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> + + + + +New/Edit Contact + + +
+

New/Edit Contact

+ + + + + + + + + + + + + + + + + + + + + + +
Name:
Email:
Address:
Telephone:
+
+
+ + \ No newline at end of file diff --git a/SpringMvcJdbcTemplate/src/main/webapp/WEB-INF/web.xml b/SpringMvcJdbcTemplate/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..84e73c2 --- /dev/null +++ b/SpringMvcJdbcTemplate/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,39 @@ + + + SpringMvcJdbcTemplate + + contextClass + + org.springframework.web.context.support.AnnotationConfigWebApplicationContext + + + + org.springframework.web.context.ContextLoaderListener + + + + SpringDispatcher + org.springframework.web.servlet.DispatcherServlet + + contextClass + + org.springframework.web.context.support.AnnotationConfigWebApplicationContext + + + + contextConfigLocation + net.codejava.spring + + 1 + + + SpringDispatcher + / + + + + 30 + + diff --git a/SpringMvcJdbcTemplate/src/main/webapp/home.jsp b/SpringMvcJdbcTemplate/src/main/webapp/home.jsp new file mode 100644 index 0000000..355483f --- /dev/null +++ b/SpringMvcJdbcTemplate/src/main/webapp/home.jsp @@ -0,0 +1,41 @@ +<%@page contentType="text/html" pageEncoding="UTF-8"%> + +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + + + + Contact Manager Home + + +
+

Contact List

+

New Contact

+ + + + + + + + + + + + + + + + + + + +
NoNameEmailAddressTelephoneAction
${status.index + 1}${contact.name}${contact.email}${contact.address}${contact.telephone} +

Edit

+ +

Delete

+
+
+ + diff --git a/SpringMvcJdbcTemplate/src/main/webapp/index.jsp b/SpringMvcJdbcTemplate/src/main/webapp/index.jsp new file mode 100644 index 0000000..14a5cfd --- /dev/null +++ b/SpringMvcJdbcTemplate/src/main/webapp/index.jsp @@ -0,0 +1,21 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> + + + + +Insert title here + + +
+ +

Welcome..!

+
+Add Customer +


+List customers + +
+ + \ No newline at end of file diff --git a/SpringMvcJdbcTemplate/src/main/webapp/resources/style.css b/SpringMvcJdbcTemplate/src/main/webapp/resources/style.css new file mode 100644 index 0000000..e69de29 diff --git a/SpringMvcJdbcTemplate/target/classes/net/codejava/spring/config/MvcConfiguration.class b/SpringMvcJdbcTemplate/target/classes/net/codejava/spring/config/MvcConfiguration.class new file mode 100644 index 0000000..a129d53 Binary files /dev/null and b/SpringMvcJdbcTemplate/target/classes/net/codejava/spring/config/MvcConfiguration.class differ diff --git a/SpringMvcJdbcTemplate/target/classes/net/codejava/spring/controller/HomeController.class b/SpringMvcJdbcTemplate/target/classes/net/codejava/spring/controller/HomeController.class new file mode 100644 index 0000000..5002b12 Binary files /dev/null and b/SpringMvcJdbcTemplate/target/classes/net/codejava/spring/controller/HomeController.class differ diff --git a/SpringMvcJdbcTemplate/target/classes/net/codejava/spring/dao/ContactDAO.class b/SpringMvcJdbcTemplate/target/classes/net/codejava/spring/dao/ContactDAO.class new file mode 100644 index 0000000..ee5e92f Binary files /dev/null and b/SpringMvcJdbcTemplate/target/classes/net/codejava/spring/dao/ContactDAO.class differ diff --git a/SpringMvcJdbcTemplate/target/classes/net/codejava/spring/dao/ContactDAOImpl$1.class b/SpringMvcJdbcTemplate/target/classes/net/codejava/spring/dao/ContactDAOImpl$1.class new file mode 100644 index 0000000..5fea445 Binary files /dev/null and b/SpringMvcJdbcTemplate/target/classes/net/codejava/spring/dao/ContactDAOImpl$1.class differ diff --git a/SpringMvcJdbcTemplate/target/classes/net/codejava/spring/dao/ContactDAOImpl$2.class b/SpringMvcJdbcTemplate/target/classes/net/codejava/spring/dao/ContactDAOImpl$2.class new file mode 100644 index 0000000..bd4a8b0 Binary files /dev/null and b/SpringMvcJdbcTemplate/target/classes/net/codejava/spring/dao/ContactDAOImpl$2.class differ diff --git a/SpringMvcJdbcTemplate/target/classes/net/codejava/spring/dao/ContactDAOImpl.class b/SpringMvcJdbcTemplate/target/classes/net/codejava/spring/dao/ContactDAOImpl.class new file mode 100644 index 0000000..77d12a6 Binary files /dev/null and b/SpringMvcJdbcTemplate/target/classes/net/codejava/spring/dao/ContactDAOImpl.class differ diff --git a/SpringMvcJdbcTemplate/target/classes/net/codejava/spring/model/Contact.class b/SpringMvcJdbcTemplate/target/classes/net/codejava/spring/model/Contact.class new file mode 100644 index 0000000..f99af0f Binary files /dev/null and b/SpringMvcJdbcTemplate/target/classes/net/codejava/spring/model/Contact.class differ diff --git a/SpringMvcJdbcTemplate/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF b/SpringMvcJdbcTemplate/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..9e36ccc --- /dev/null +++ b/SpringMvcJdbcTemplate/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Built-By: ABBURI'S +Build-Jdk: 1.8.0_101 +Created-By: Maven Integration for Eclipse + diff --git a/SpringMvcJdbcTemplate/target/m2e-wtp/web-resources/META-INF/maven/net.codejava.spring/SpringMvcJdbcTemplate/pom.properties b/SpringMvcJdbcTemplate/target/m2e-wtp/web-resources/META-INF/maven/net.codejava.spring/SpringMvcJdbcTemplate/pom.properties new file mode 100644 index 0000000..9411097 --- /dev/null +++ b/SpringMvcJdbcTemplate/target/m2e-wtp/web-resources/META-INF/maven/net.codejava.spring/SpringMvcJdbcTemplate/pom.properties @@ -0,0 +1,7 @@ +#Generated by Maven Integration for Eclipse +#Wed Nov 16 20:01:12 EST 2016 +version=1.0 +groupId=net.codejava.spring +m2e.projectName=SpringMvcJdbcTemplate +m2e.projectLocation=C\:\\Users\\ABBURI'S\\sts\\SpringMvcJdbcTemplate +artifactId=SpringMvcJdbcTemplate diff --git a/SpringMvcJdbcTemplate/target/m2e-wtp/web-resources/META-INF/maven/net.codejava.spring/SpringMvcJdbcTemplate/pom.xml b/SpringMvcJdbcTemplate/target/m2e-wtp/web-resources/META-INF/maven/net.codejava.spring/SpringMvcJdbcTemplate/pom.xml new file mode 100644 index 0000000..f54e7c5 --- /dev/null +++ b/SpringMvcJdbcTemplate/target/m2e-wtp/web-resources/META-INF/maven/net.codejava.spring/SpringMvcJdbcTemplate/pom.xml @@ -0,0 +1,84 @@ + + + 4.0.0 + + net.codejava.spring + SpringMvcJdbcTemplate + 1.0 + war + + SpringMvcJdbcTemplate + http://maven.apache.org + + + 1.7 + 4.0.3.RELEASE + 2.2.2 + + + + + + org.springframework + spring-context + ${spring.version} + + + + org.springframework + spring-webmvc + ${spring.version} + + + org.springframework + spring-orm + ${spring.version} + jar + compile + + + + + cglib + cglib-nodep + ${cglib.version} + runtime + + + + + + javax.servlet + javax.servlet-api + 3.1.0 + provided + + + javax.servlet.jsp + javax.servlet.jsp-api + 2.3.1 + provided + + + jstl + jstl + 1.2 + + + + + + SpringMvcJdbcTemplate + + + org.apache.maven.plugins + maven-compiler-plugin + 2.0.2 + + ${java.version} + ${java.version} + + + + + diff --git a/StrutsPractice4/.classpath b/StrutsPractice4/.classpath new file mode 100644 index 0000000..f264e7f --- /dev/null +++ b/StrutsPractice4/.classpath @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StrutsPractice4/.project b/StrutsPractice4/.project new file mode 100644 index 0000000..7f90cd1 --- /dev/null +++ b/StrutsPractice4/.project @@ -0,0 +1,42 @@ + + + StrutsPractice4 + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/StrutsPractice4/.settings/.jsdtscope b/StrutsPractice4/.settings/.jsdtscope new file mode 100644 index 0000000..92e666d --- /dev/null +++ b/StrutsPractice4/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/StrutsPractice4/.settings/org.eclipse.jdt.core.prefs b/StrutsPractice4/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..6e80039 --- /dev/null +++ b/StrutsPractice4/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/StrutsPractice4/.settings/org.eclipse.m2e.core.prefs b/StrutsPractice4/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/StrutsPractice4/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/StrutsPractice4/.settings/org.eclipse.wst.common.component b/StrutsPractice4/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..3e163ec --- /dev/null +++ b/StrutsPractice4/.settings/org.eclipse.wst.common.component @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/StrutsPractice4/.settings/org.eclipse.wst.common.project.facet.core.xml b/StrutsPractice4/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..d5aea72 --- /dev/null +++ b/StrutsPractice4/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/StrutsPractice4/.settings/org.eclipse.wst.jsdt.ui.superType.container b/StrutsPractice4/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/StrutsPractice4/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/StrutsPractice4/.settings/org.eclipse.wst.jsdt.ui.superType.name b/StrutsPractice4/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/StrutsPractice4/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/StrutsPractice4/.settings/org.eclipse.wst.validation.prefs b/StrutsPractice4/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..04cad8c --- /dev/null +++ b/StrutsPractice4/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/StrutsPractice4/WebContent/META-INF/MANIFEST.MF b/StrutsPractice4/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/StrutsPractice4/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/StrutsPractice4/WebContent/WEB-INF/web.xml b/StrutsPractice4/WebContent/WEB-INF/web.xml new file mode 100644 index 0000000..4cee73a --- /dev/null +++ b/StrutsPractice4/WebContent/WEB-INF/web.xml @@ -0,0 +1,16 @@ + + + StrutsPractice + + index.jsp + + + struts2 + org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter + + + struts2 + /* + + + \ No newline at end of file diff --git a/StrutsPractice4/WebContent/edit.jsp b/StrutsPractice4/WebContent/edit.jsp new file mode 100644 index 0000000..521ee70 --- /dev/null +++ b/StrutsPractice4/WebContent/edit.jsp @@ -0,0 +1,23 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@taglib prefix="s" uri="/struts-tags"%> + + + + +edit + + +
+

edit user

+ + + + + + + + +
+ + \ No newline at end of file diff --git a/StrutsPractice4/WebContent/error.jsp b/StrutsPractice4/WebContent/error.jsp new file mode 100644 index 0000000..1f770dc --- /dev/null +++ b/StrutsPractice4/WebContent/error.jsp @@ -0,0 +1,12 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +error page + + +Error occured! + + \ No newline at end of file diff --git a/StrutsPractice4/WebContent/index.jsp b/StrutsPractice4/WebContent/index.jsp new file mode 100644 index 0000000..26e3df6 --- /dev/null +++ b/StrutsPractice4/WebContent/index.jsp @@ -0,0 +1,21 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@taglib prefix="s" uri="/struts-tags" %> + + + + +index page + + +
+

Hello World From Struts2

+ + + + + + +
+ + \ No newline at end of file diff --git a/StrutsPractice4/WebContent/list.jsp b/StrutsPractice4/WebContent/list.jsp new file mode 100644 index 0000000..967df6f --- /dev/null +++ b/StrutsPractice4/WebContent/list.jsp @@ -0,0 +1,55 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@ taglib prefix="s" uri="/struts-tags"%> + + + + +list + +

+Add new customer

+

Customer list

+ + + + + + + + + + + + + + + + + +
NAMEEMAILPHONEEDIT/DELETE
+ + + + + + + + +
+ + + + + + +
+ + + + +
+
+ + + \ No newline at end of file diff --git a/StrutsPractice4/WebContent/save.jsp b/StrutsPractice4/WebContent/save.jsp new file mode 100644 index 0000000..2638000 --- /dev/null +++ b/StrutsPractice4/WebContent/save.jsp @@ -0,0 +1,16 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@taglib prefix="s" uri="/struts-tags"%> + + + + +save page + + +

Save success...!!!!!!

+ + + + + \ No newline at end of file diff --git a/StrutsPractice4/pom.xml b/StrutsPractice4/pom.xml new file mode 100644 index 0000000..7c09e98 --- /dev/null +++ b/StrutsPractice4/pom.xml @@ -0,0 +1,35 @@ + + 4.0.0 + StrutsPractice4 + StrutsPractice4 + 0.0.1-SNAPSHOT + war + + src + + + maven-compiler-plugin + 3.3 + + 1.8 + 1.8 + + + + maven-war-plugin + 2.6 + + WebContent + false + + + + + + + org.apache.struts + struts2-core + 2.5.5 + + + \ No newline at end of file diff --git a/StrutsPractice4/src/org/abburi/practice/action/DeleteCustomerAction.java b/StrutsPractice4/src/org/abburi/practice/action/DeleteCustomerAction.java new file mode 100644 index 0000000..650985e --- /dev/null +++ b/StrutsPractice4/src/org/abburi/practice/action/DeleteCustomerAction.java @@ -0,0 +1,31 @@ +package org.abburi.practice.action; + +import org.abburi.practice.dao.CustomerDao; +import org.abburi.practice.dto.Customer; + +public class DeleteCustomerAction { + + private Customer customer; + private CustomerDao dao; + + public Customer getCustomer() { + return customer; + } + + public void setCustomer(Customer customer) { + this.customer = customer; + } + + public String execute() throws Exception { + System.out.println("delete param = "+getCustomer().getName()); + dao = new CustomerDao(); + int deletedUser=dao.deleteUser(getCustomer().getName()); + if(deletedUser>0){ + return "success"; + } + else{ + return "error"; + } + } +} + diff --git a/StrutsPractice4/src/org/abburi/practice/action/EditAction.java b/StrutsPractice4/src/org/abburi/practice/action/EditAction.java new file mode 100644 index 0000000..75a5d5a --- /dev/null +++ b/StrutsPractice4/src/org/abburi/practice/action/EditAction.java @@ -0,0 +1,25 @@ +package org.abburi.practice.action; + +import org.abburi.practice.dto.Customer; + +import com.opensymphony.xwork2.ActionSupport; + +public class EditAction extends ActionSupport{ + /** + * + */ + private static final long serialVersionUID = 1L; + private Customer customer; + public String editCustomer() throws Exception { + System.out.println("Edit name = "+getCustomer().getName()); + System.out.println("Edit email = "+getCustomer().getEmail()); + System.out.println("Edit phone = "+getCustomer().getPhone()); + return SUCCESS; + } + public Customer getCustomer() { + return customer; + } + public void setCustomer(Customer customer) { + this.customer = customer; + } +} diff --git a/StrutsPractice4/src/org/abburi/practice/action/LoadCustomersAction.java b/StrutsPractice4/src/org/abburi/practice/action/LoadCustomersAction.java new file mode 100644 index 0000000..6ea0c5f --- /dev/null +++ b/StrutsPractice4/src/org/abburi/practice/action/LoadCustomersAction.java @@ -0,0 +1,37 @@ +package org.abburi.practice.action; + +import java.util.List; + +import org.abburi.practice.dao.CustomerDao; +import org.abburi.practice.dto.Customer; + +import com.opensymphony.xwork2.ActionSupport; + +public class LoadCustomersAction extends ActionSupport{ + + private static final long serialVersionUID = 1L; +private List custlist; + + +public List getCustlist() { + return custlist; +} + + +public void setCustlist(List custlist) { + this.custlist = custlist; +} + + +public String list() throws Exception{ + CustomerDao dao= new CustomerDao(); + setCustlist(dao.listAllCustomers()); + + if(getCustlist().size()>0){ + return SUCCESS; + } + else{ + return ERROR; + } +} +} \ No newline at end of file diff --git a/StrutsPractice4/src/org/abburi/practice/action/SaveAction.java b/StrutsPractice4/src/org/abburi/practice/action/SaveAction.java new file mode 100644 index 0000000..fe8025a --- /dev/null +++ b/StrutsPractice4/src/org/abburi/practice/action/SaveAction.java @@ -0,0 +1,28 @@ +package org.abburi.practice.action; + +import org.abburi.practice.dao.CustomerDao; +import org.abburi.practice.dto.Customer; + +public class SaveAction { + + + + private Customer customer; + private CustomerDao dao; + + public Customer getCustomer() { + return customer; + } + + public void setCustomer(Customer customer) { + this.customer = customer; + } + + public String execute() throws Exception { + dao = new CustomerDao(); + dao.saveUser(customer); + return "success"; +// return SUCCESS; + } +} + diff --git a/StrutsPractice4/src/org/abburi/practice/action/UpdateCustomerAction.java b/StrutsPractice4/src/org/abburi/practice/action/UpdateCustomerAction.java new file mode 100644 index 0000000..64500c5 --- /dev/null +++ b/StrutsPractice4/src/org/abburi/practice/action/UpdateCustomerAction.java @@ -0,0 +1,57 @@ +package org.abburi.practice.action; + +import org.abburi.practice.dao.CustomerDao; +import org.abburi.practice.dto.Customer; + +import com.opensymphony.xwork2.ActionSupport; + +public class UpdateCustomerAction extends ActionSupport{ + + + /** + * + */ + private static final long serialVersionUID = 1L; + private Customer customer; + private String oldName; + + + + public Customer getCustomer() { + return customer; + } + + public void setCustomer(Customer customer) { + this.customer = customer; + } + + public String updateCustomer() throws Exception{ + CustomerDao dao = new CustomerDao(); + String name=customer.getName(); + System.out.println("name:"+name); + String email = customer.getEmail(); + System.out.println("email:"+ email); + String phone = customer.getPhone(); + System.out.println("phone:"+phone); + String oldName=getOldName(); + System.out.println("oldName:"+ oldName); + int updatedUser=dao.updateUser(name, email, phone, oldName); + System.out.println(updatedUser); + if(updatedUser==1){ + return "success"; + } + else{ + return "error"; + } + } + + public String getOldName() { + return oldName; + } + + public void setOldName(String oldName) { + this.oldName = oldName; + } + +} + diff --git a/StrutsPractice4/src/org/abburi/practice/dao/CustomerDao.java b/StrutsPractice4/src/org/abburi/practice/dao/CustomerDao.java new file mode 100644 index 0000000..880cadd --- /dev/null +++ b/StrutsPractice4/src/org/abburi/practice/dao/CustomerDao.java @@ -0,0 +1,102 @@ +package org.abburi.practice.dao; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +import org.abburi.practice.dto.Customer; + +public class CustomerDao { + String sql; + String url="jdbc:mysql://localhost:3306/empdb"; + String uname="root"; + String passwd="root"; + Connection con=null; + + + + public CustomerDao() { + super(); + try { + openConnection(); + } catch (Exception e) { + e.printStackTrace(); + } + } +public Connection openConnection() throws Exception{ + Class.forName("com.mysql.jdbc.Driver"); + con=DriverManager.getConnection(url,uname,passwd); + return con; + } + public int saveUser(Customer cust) throws Exception{ + sql="insert into empdb.strutsdata(name,email,phone) values(?,?,?)"; + PreparedStatement ps=con.prepareStatement(sql); + ps.setString(1, cust.getName()); + ps.setString(2, cust.getEmail()); + ps.setString(3, cust.getPhone()); + int saveCount=ps.executeUpdate(); + if(saveCount>0){ + System.out.println("save success"); + } + else{ + System.out.println("Try again"); + } + return saveCount; + } + public int updateUser(String name, String email, String phone, String oldName) throws Exception{ + sql="update empdb.strutsdata set name=?, email=?,phone=? where name=?"; + PreparedStatement ps=con.prepareStatement(sql); + System.out.println(sql); + ps.setString(1, name); + ps.setString(2, email); + ps.setString(3, phone); + ps.setString(4, oldName); + + int updateCount=ps.executeUpdate(); + if(updateCount>0){ + System.out.println("update success"); + } + else{ + System.out.println("Try again"); + } + return updateCount; + } + public int deleteUser(String name) throws Exception{ + sql="delete from strutsdata where name='"+name+"' "; + System.out.println(sql); + PreparedStatement ps=con.prepareStatement(sql); + int deleteCount=ps.executeUpdate(); + if(deleteCount>0){ + System.out.println("delete success"); + } + else{ + System.out.println("Try again"); + } + return deleteCount; + } + public List listAllCustomers() throws Exception{ + List list= new ArrayList(); + sql="select * from strutsdata"; + Statement st=con.createStatement(); + ResultSet rs=st.executeQuery(sql); + while(rs.next()){ + + list.add(buildCustomer(rs.getString(1), rs.getString(2), rs.getString(3))); + } + return list; + + } + public Customer buildCustomer(String name,String email,String phone){ + Customer customer; + customer=new Customer(); + customer.setName(name); + customer.setEmail(email); + customer.setPhone(phone); + return customer; + + } +} diff --git a/StrutsPractice4/src/org/abburi/practice/dto/Customer.java b/StrutsPractice4/src/org/abburi/practice/dto/Customer.java new file mode 100644 index 0000000..4acc67b --- /dev/null +++ b/StrutsPractice4/src/org/abburi/practice/dto/Customer.java @@ -0,0 +1,26 @@ +package org.abburi.practice.dto; + +public class Customer { +private String name; +private String email; +private String phone; +public String getName() { + return name; +} +public void setName(String name) { + this.name = name; +} +public String getEmail() { + return email; +} +public void setEmail(String email) { + this.email = email; +} +public String getPhone() { + return phone; +} +public void setPhone(String phone) { + this.phone = phone; +} + +} diff --git a/StrutsPractice4/src/struts.xml b/StrutsPractice4/src/struts.xml new file mode 100644 index 0000000..c7043dd --- /dev/null +++ b/StrutsPractice4/src/struts.xml @@ -0,0 +1,29 @@ + + + + + + + listCustomers + /error.jsp + + + /list.jsp + /error.jsp + + + listCustomers + /error.jsp + + + /edit.jsp + /error.jsp + + + listCustomers + /error.jsp + + + \ No newline at end of file diff --git a/StrutsPractice4/target/classes/org/abburi/practice/action/DeleteCustomerAction.class b/StrutsPractice4/target/classes/org/abburi/practice/action/DeleteCustomerAction.class new file mode 100644 index 0000000..fd0155b Binary files /dev/null and b/StrutsPractice4/target/classes/org/abburi/practice/action/DeleteCustomerAction.class differ diff --git a/StrutsPractice4/target/classes/org/abburi/practice/action/EditAction.class b/StrutsPractice4/target/classes/org/abburi/practice/action/EditAction.class new file mode 100644 index 0000000..d8224a4 Binary files /dev/null and b/StrutsPractice4/target/classes/org/abburi/practice/action/EditAction.class differ diff --git a/StrutsPractice4/target/classes/org/abburi/practice/action/LoadCustomersAction.class b/StrutsPractice4/target/classes/org/abburi/practice/action/LoadCustomersAction.class new file mode 100644 index 0000000..98c3472 Binary files /dev/null and b/StrutsPractice4/target/classes/org/abburi/practice/action/LoadCustomersAction.class differ diff --git a/StrutsPractice4/target/classes/org/abburi/practice/action/SaveAction.class b/StrutsPractice4/target/classes/org/abburi/practice/action/SaveAction.class new file mode 100644 index 0000000..5d28d3d Binary files /dev/null and b/StrutsPractice4/target/classes/org/abburi/practice/action/SaveAction.class differ diff --git a/StrutsPractice4/target/classes/org/abburi/practice/action/UpdateCustomerAction.class b/StrutsPractice4/target/classes/org/abburi/practice/action/UpdateCustomerAction.class new file mode 100644 index 0000000..b01c7a4 Binary files /dev/null and b/StrutsPractice4/target/classes/org/abburi/practice/action/UpdateCustomerAction.class differ diff --git a/StrutsPractice4/target/classes/org/abburi/practice/dao/CustomerDao.class b/StrutsPractice4/target/classes/org/abburi/practice/dao/CustomerDao.class new file mode 100644 index 0000000..06d4dc0 Binary files /dev/null and b/StrutsPractice4/target/classes/org/abburi/practice/dao/CustomerDao.class differ diff --git a/StrutsPractice4/target/classes/org/abburi/practice/dto/Customer.class b/StrutsPractice4/target/classes/org/abburi/practice/dto/Customer.class new file mode 100644 index 0000000..62407c2 Binary files /dev/null and b/StrutsPractice4/target/classes/org/abburi/practice/dto/Customer.class differ diff --git a/StrutsPractice4/target/classes/struts.xml b/StrutsPractice4/target/classes/struts.xml new file mode 100644 index 0000000..c7043dd --- /dev/null +++ b/StrutsPractice4/target/classes/struts.xml @@ -0,0 +1,29 @@ + + + + + + + listCustomers + /error.jsp + + + /list.jsp + /error.jsp + + + listCustomers + /error.jsp + + + /edit.jsp + /error.jsp + + + listCustomers + /error.jsp + + + \ No newline at end of file diff --git a/StrutsPractice4/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF b/StrutsPractice4/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..9e36ccc --- /dev/null +++ b/StrutsPractice4/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Built-By: ABBURI'S +Build-Jdk: 1.8.0_101 +Created-By: Maven Integration for Eclipse + diff --git a/StrutsPractice4/target/m2e-wtp/web-resources/META-INF/maven/StrutsPractice4/StrutsPractice4/pom.properties b/StrutsPractice4/target/m2e-wtp/web-resources/META-INF/maven/StrutsPractice4/StrutsPractice4/pom.properties new file mode 100644 index 0000000..c1475b7 --- /dev/null +++ b/StrutsPractice4/target/m2e-wtp/web-resources/META-INF/maven/StrutsPractice4/StrutsPractice4/pom.properties @@ -0,0 +1,7 @@ +#Generated by Maven Integration for Eclipse +#Mon Nov 14 12:57:21 EST 2016 +version=0.0.1-SNAPSHOT +groupId=StrutsPractice4 +m2e.projectName=StrutsPractice4 +m2e.projectLocation=C\:\\Users\\ABBURI'S\\workspace2\\StrutsPractice4 +artifactId=StrutsPractice4 diff --git a/StrutsPractice4/target/m2e-wtp/web-resources/META-INF/maven/StrutsPractice4/StrutsPractice4/pom.xml b/StrutsPractice4/target/m2e-wtp/web-resources/META-INF/maven/StrutsPractice4/StrutsPractice4/pom.xml new file mode 100644 index 0000000..7c09e98 --- /dev/null +++ b/StrutsPractice4/target/m2e-wtp/web-resources/META-INF/maven/StrutsPractice4/StrutsPractice4/pom.xml @@ -0,0 +1,35 @@ + + 4.0.0 + StrutsPractice4 + StrutsPractice4 + 0.0.1-SNAPSHOT + war + + src + + + maven-compiler-plugin + 3.3 + + 1.8 + 1.8 + + + + maven-war-plugin + 2.6 + + WebContent + false + + + + + + + org.apache.struts + struts2-core + 2.5.5 + + + \ No newline at end of file diff --git a/StrutsValidation/.classpath b/StrutsValidation/.classpath new file mode 100644 index 0000000..b9d618d --- /dev/null +++ b/StrutsValidation/.classpath @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/StrutsValidation/.project b/StrutsValidation/.project new file mode 100644 index 0000000..f37dcb6 --- /dev/null +++ b/StrutsValidation/.project @@ -0,0 +1,37 @@ + + + StrutsValidation + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/StrutsValidation/.settings/.jsdtscope b/StrutsValidation/.settings/.jsdtscope new file mode 100644 index 0000000..92e666d --- /dev/null +++ b/StrutsValidation/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/StrutsValidation/.settings/org.eclipse.jdt.core.prefs b/StrutsValidation/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..6e80039 --- /dev/null +++ b/StrutsValidation/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/StrutsValidation/.settings/org.eclipse.m2e.core.prefs b/StrutsValidation/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/StrutsValidation/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/StrutsValidation/.settings/org.eclipse.wst.common.component b/StrutsValidation/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..09e1877 --- /dev/null +++ b/StrutsValidation/.settings/org.eclipse.wst.common.component @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/StrutsValidation/.settings/org.eclipse.wst.common.project.facet.core.xml b/StrutsValidation/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..bb5ef46 --- /dev/null +++ b/StrutsValidation/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/StrutsValidation/.settings/org.eclipse.wst.jsdt.ui.superType.container b/StrutsValidation/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/StrutsValidation/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/StrutsValidation/.settings/org.eclipse.wst.jsdt.ui.superType.name b/StrutsValidation/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/StrutsValidation/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/StrutsValidation/.settings/org.eclipse.wst.validation.prefs b/StrutsValidation/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..04cad8c --- /dev/null +++ b/StrutsValidation/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/StrutsValidation/WebContent/META-INF/MANIFEST.MF b/StrutsValidation/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/StrutsValidation/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/StrutsValidation/WebContent/WEB-INF/web.xml b/StrutsValidation/WebContent/WEB-INF/web.xml new file mode 100644 index 0000000..558dd4a --- /dev/null +++ b/StrutsValidation/WebContent/WEB-INF/web.xml @@ -0,0 +1,16 @@ + + + StrutsValidation + + index.jsp + + + struts2 + org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter + + + struts2 + /* + + + \ No newline at end of file diff --git a/StrutsValidation/WebContent/edit.jsp b/StrutsValidation/WebContent/edit.jsp new file mode 100644 index 0000000..6f3ed52 --- /dev/null +++ b/StrutsValidation/WebContent/edit.jsp @@ -0,0 +1,24 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@taglib prefix="s" uri="/struts-tags"%> + + + + +edit + + + +
+

edit user

+ + + + + + + + +
+ + \ No newline at end of file diff --git a/StrutsValidation/WebContent/error.jsp b/StrutsValidation/WebContent/error.jsp new file mode 100644 index 0000000..1f770dc --- /dev/null +++ b/StrutsValidation/WebContent/error.jsp @@ -0,0 +1,12 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +error page + + +Error occured! + + \ No newline at end of file diff --git a/StrutsValidation/WebContent/index.jsp b/StrutsValidation/WebContent/index.jsp new file mode 100644 index 0000000..69b9cb0 --- /dev/null +++ b/StrutsValidation/WebContent/index.jsp @@ -0,0 +1,22 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@taglib prefix="s" uri="/struts-tags" %> + + + + + +index page + + +
+

Hello World From Struts2

+ + + + + + +
+ + \ No newline at end of file diff --git a/StrutsValidation/WebContent/list.jsp b/StrutsValidation/WebContent/list.jsp new file mode 100644 index 0000000..967df6f --- /dev/null +++ b/StrutsValidation/WebContent/list.jsp @@ -0,0 +1,55 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@ taglib prefix="s" uri="/struts-tags"%> + + + + +list + +

+Add new customer

+

Customer list

+ + + + + + + + + + + + + + + + + +
NAMEEMAILPHONEEDIT/DELETE
+ + + + + + + + +
+ + + + + + +
+ + + + +
+
+ + + \ No newline at end of file diff --git a/StrutsValidation/WebContent/save.jsp b/StrutsValidation/WebContent/save.jsp new file mode 100644 index 0000000..2638000 --- /dev/null +++ b/StrutsValidation/WebContent/save.jsp @@ -0,0 +1,16 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@taglib prefix="s" uri="/struts-tags"%> + + + + +save page + + +

Save success...!!!!!!

+ + + + + \ No newline at end of file diff --git a/StrutsValidation/build/classes/org/abburi/practice/action/DeleteCustomerAction.class b/StrutsValidation/build/classes/org/abburi/practice/action/DeleteCustomerAction.class new file mode 100644 index 0000000..fd0155b Binary files /dev/null and b/StrutsValidation/build/classes/org/abburi/practice/action/DeleteCustomerAction.class differ diff --git a/StrutsValidation/build/classes/org/abburi/practice/action/EditAction.class b/StrutsValidation/build/classes/org/abburi/practice/action/EditAction.class new file mode 100644 index 0000000..170b2b0 Binary files /dev/null and b/StrutsValidation/build/classes/org/abburi/practice/action/EditAction.class differ diff --git a/StrutsValidation/build/classes/org/abburi/practice/action/LoadCustomersAction.class b/StrutsValidation/build/classes/org/abburi/practice/action/LoadCustomersAction.class new file mode 100644 index 0000000..bc92959 Binary files /dev/null and b/StrutsValidation/build/classes/org/abburi/practice/action/LoadCustomersAction.class differ diff --git a/StrutsValidation/build/classes/org/abburi/practice/action/SaveAction.class b/StrutsValidation/build/classes/org/abburi/practice/action/SaveAction.class new file mode 100644 index 0000000..5d28d3d Binary files /dev/null and b/StrutsValidation/build/classes/org/abburi/practice/action/SaveAction.class differ diff --git a/StrutsValidation/build/classes/org/abburi/practice/action/UpdateCustomerAction.class b/StrutsValidation/build/classes/org/abburi/practice/action/UpdateCustomerAction.class new file mode 100644 index 0000000..9ff71dc Binary files /dev/null and b/StrutsValidation/build/classes/org/abburi/practice/action/UpdateCustomerAction.class differ diff --git a/StrutsValidation/build/classes/org/abburi/practice/dao/CustomerDao.class b/StrutsValidation/build/classes/org/abburi/practice/dao/CustomerDao.class new file mode 100644 index 0000000..06d4dc0 Binary files /dev/null and b/StrutsValidation/build/classes/org/abburi/practice/dao/CustomerDao.class differ diff --git a/StrutsValidation/build/classes/org/abburi/practice/dto/Customer.class b/StrutsValidation/build/classes/org/abburi/practice/dto/Customer.class new file mode 100644 index 0000000..62407c2 Binary files /dev/null and b/StrutsValidation/build/classes/org/abburi/practice/dto/Customer.class differ diff --git a/StrutsValidation/build/classes/struts.xml b/StrutsValidation/build/classes/struts.xml new file mode 100644 index 0000000..c7043dd --- /dev/null +++ b/StrutsValidation/build/classes/struts.xml @@ -0,0 +1,29 @@ + + + + + + + listCustomers + /error.jsp + + + /list.jsp + /error.jsp + + + listCustomers + /error.jsp + + + /edit.jsp + /error.jsp + + + listCustomers + /error.jsp + + + \ No newline at end of file diff --git a/StrutsValidation/pom.xml b/StrutsValidation/pom.xml new file mode 100644 index 0000000..2763c5a --- /dev/null +++ b/StrutsValidation/pom.xml @@ -0,0 +1,42 @@ + + 4.0.0 + StrutsInterceptor + StrutsInterceptor + 0.0.1-SNAPSHOT + war + + src + + + src + + **/*.java + + + + + + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + + maven-war-plugin + 3.0.0 + + WebContent + + + + + + + org.apache.struts + struts2-core + 2.5.5 + + + \ No newline at end of file diff --git a/StrutsValidation/resources/ApplicationResources.properties b/StrutsValidation/resources/ApplicationResources.properties new file mode 100644 index 0000000..ea9d231 --- /dev/null +++ b/StrutsValidation/resources/ApplicationResources.properties @@ -0,0 +1,9 @@ +name= Name +email= Email +phone= Phone +label.add.customer=Add Customer +label.update.customer= Update Customer + +errors.invalid=${getText(fieldName)} is invalid. +errors.required=${getText(fieldName)} is required. +errors.number=${getText(fieldName)} must be a number. \ No newline at end of file diff --git a/StrutsValidation/resources/struts.xml b/StrutsValidation/resources/struts.xml new file mode 100644 index 0000000..a513fbf --- /dev/null +++ b/StrutsValidation/resources/struts.xml @@ -0,0 +1,32 @@ + + + + + + + + + listCustomers + /index.jsp + + + /list.jsp + /error.jsp + + + listCustomers + /error.jsp + + + /edit.jsp + /error.jsp + + + listCustomers + /error.jsp + /edit.jsp + + + \ No newline at end of file diff --git a/StrutsValidation/src/org/abburi/practice/action/DeleteCustomerAction.java b/StrutsValidation/src/org/abburi/practice/action/DeleteCustomerAction.java new file mode 100644 index 0000000..650985e --- /dev/null +++ b/StrutsValidation/src/org/abburi/practice/action/DeleteCustomerAction.java @@ -0,0 +1,31 @@ +package org.abburi.practice.action; + +import org.abburi.practice.dao.CustomerDao; +import org.abburi.practice.dto.Customer; + +public class DeleteCustomerAction { + + private Customer customer; + private CustomerDao dao; + + public Customer getCustomer() { + return customer; + } + + public void setCustomer(Customer customer) { + this.customer = customer; + } + + public String execute() throws Exception { + System.out.println("delete param = "+getCustomer().getName()); + dao = new CustomerDao(); + int deletedUser=dao.deleteUser(getCustomer().getName()); + if(deletedUser>0){ + return "success"; + } + else{ + return "error"; + } + } +} + diff --git a/StrutsValidation/src/org/abburi/practice/action/EditAction.java b/StrutsValidation/src/org/abburi/practice/action/EditAction.java new file mode 100644 index 0000000..75a5d5a --- /dev/null +++ b/StrutsValidation/src/org/abburi/practice/action/EditAction.java @@ -0,0 +1,25 @@ +package org.abburi.practice.action; + +import org.abburi.practice.dto.Customer; + +import com.opensymphony.xwork2.ActionSupport; + +public class EditAction extends ActionSupport{ + /** + * + */ + private static final long serialVersionUID = 1L; + private Customer customer; + public String editCustomer() throws Exception { + System.out.println("Edit name = "+getCustomer().getName()); + System.out.println("Edit email = "+getCustomer().getEmail()); + System.out.println("Edit phone = "+getCustomer().getPhone()); + return SUCCESS; + } + public Customer getCustomer() { + return customer; + } + public void setCustomer(Customer customer) { + this.customer = customer; + } +} diff --git a/StrutsValidation/src/org/abburi/practice/action/LoadCustomersAction.java b/StrutsValidation/src/org/abburi/practice/action/LoadCustomersAction.java new file mode 100644 index 0000000..6ea0c5f --- /dev/null +++ b/StrutsValidation/src/org/abburi/practice/action/LoadCustomersAction.java @@ -0,0 +1,37 @@ +package org.abburi.practice.action; + +import java.util.List; + +import org.abburi.practice.dao.CustomerDao; +import org.abburi.practice.dto.Customer; + +import com.opensymphony.xwork2.ActionSupport; + +public class LoadCustomersAction extends ActionSupport{ + + private static final long serialVersionUID = 1L; +private List custlist; + + +public List getCustlist() { + return custlist; +} + + +public void setCustlist(List custlist) { + this.custlist = custlist; +} + + +public String list() throws Exception{ + CustomerDao dao= new CustomerDao(); + setCustlist(dao.listAllCustomers()); + + if(getCustlist().size()>0){ + return SUCCESS; + } + else{ + return ERROR; + } +} +} \ No newline at end of file diff --git a/StrutsValidation/src/org/abburi/practice/action/SaveAction-validation.xml b/StrutsValidation/src/org/abburi/practice/action/SaveAction-validation.xml new file mode 100644 index 0000000..25eca45 --- /dev/null +++ b/StrutsValidation/src/org/abburi/practice/action/SaveAction-validation.xml @@ -0,0 +1,24 @@ + + + + + + true + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StrutsValidation/src/org/abburi/practice/action/SaveAction.java b/StrutsValidation/src/org/abburi/practice/action/SaveAction.java new file mode 100644 index 0000000..ad0f12d --- /dev/null +++ b/StrutsValidation/src/org/abburi/practice/action/SaveAction.java @@ -0,0 +1,34 @@ +package org.abburi.practice.action; + +import org.abburi.practice.dao.CustomerDao; +import org.abburi.practice.dto.Customer; + +import com.opensymphony.xwork2.ActionSupport; + +public class SaveAction extends ActionSupport{ + + + + /** + * + */ + private static final long serialVersionUID = 1L; + private Customer customer; + private CustomerDao dao; + + public Customer getCustomer() { + return customer; + } + + public void setCustomer(Customer customer) { + this.customer = customer; + } + + public String addCustomer() throws Exception { + dao = new CustomerDao(); + dao.saveUser(customer); + return "success"; +// return SUCCESS; + } +} + diff --git a/StrutsValidation/src/org/abburi/practice/action/UpdateCustomerAction-validation.xml b/StrutsValidation/src/org/abburi/practice/action/UpdateCustomerAction-validation.xml new file mode 100644 index 0000000..25eca45 --- /dev/null +++ b/StrutsValidation/src/org/abburi/practice/action/UpdateCustomerAction-validation.xml @@ -0,0 +1,24 @@ + + + + + + true + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StrutsValidation/src/org/abburi/practice/action/UpdateCustomerAction.java b/StrutsValidation/src/org/abburi/practice/action/UpdateCustomerAction.java new file mode 100644 index 0000000..64500c5 --- /dev/null +++ b/StrutsValidation/src/org/abburi/practice/action/UpdateCustomerAction.java @@ -0,0 +1,57 @@ +package org.abburi.practice.action; + +import org.abburi.practice.dao.CustomerDao; +import org.abburi.practice.dto.Customer; + +import com.opensymphony.xwork2.ActionSupport; + +public class UpdateCustomerAction extends ActionSupport{ + + + /** + * + */ + private static final long serialVersionUID = 1L; + private Customer customer; + private String oldName; + + + + public Customer getCustomer() { + return customer; + } + + public void setCustomer(Customer customer) { + this.customer = customer; + } + + public String updateCustomer() throws Exception{ + CustomerDao dao = new CustomerDao(); + String name=customer.getName(); + System.out.println("name:"+name); + String email = customer.getEmail(); + System.out.println("email:"+ email); + String phone = customer.getPhone(); + System.out.println("phone:"+phone); + String oldName=getOldName(); + System.out.println("oldName:"+ oldName); + int updatedUser=dao.updateUser(name, email, phone, oldName); + System.out.println(updatedUser); + if(updatedUser==1){ + return "success"; + } + else{ + return "error"; + } + } + + public String getOldName() { + return oldName; + } + + public void setOldName(String oldName) { + this.oldName = oldName; + } + +} + diff --git a/StrutsValidation/src/org/abburi/practice/dao/CustomerDao.java b/StrutsValidation/src/org/abburi/practice/dao/CustomerDao.java new file mode 100644 index 0000000..880cadd --- /dev/null +++ b/StrutsValidation/src/org/abburi/practice/dao/CustomerDao.java @@ -0,0 +1,102 @@ +package org.abburi.practice.dao; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +import org.abburi.practice.dto.Customer; + +public class CustomerDao { + String sql; + String url="jdbc:mysql://localhost:3306/empdb"; + String uname="root"; + String passwd="root"; + Connection con=null; + + + + public CustomerDao() { + super(); + try { + openConnection(); + } catch (Exception e) { + e.printStackTrace(); + } + } +public Connection openConnection() throws Exception{ + Class.forName("com.mysql.jdbc.Driver"); + con=DriverManager.getConnection(url,uname,passwd); + return con; + } + public int saveUser(Customer cust) throws Exception{ + sql="insert into empdb.strutsdata(name,email,phone) values(?,?,?)"; + PreparedStatement ps=con.prepareStatement(sql); + ps.setString(1, cust.getName()); + ps.setString(2, cust.getEmail()); + ps.setString(3, cust.getPhone()); + int saveCount=ps.executeUpdate(); + if(saveCount>0){ + System.out.println("save success"); + } + else{ + System.out.println("Try again"); + } + return saveCount; + } + public int updateUser(String name, String email, String phone, String oldName) throws Exception{ + sql="update empdb.strutsdata set name=?, email=?,phone=? where name=?"; + PreparedStatement ps=con.prepareStatement(sql); + System.out.println(sql); + ps.setString(1, name); + ps.setString(2, email); + ps.setString(3, phone); + ps.setString(4, oldName); + + int updateCount=ps.executeUpdate(); + if(updateCount>0){ + System.out.println("update success"); + } + else{ + System.out.println("Try again"); + } + return updateCount; + } + public int deleteUser(String name) throws Exception{ + sql="delete from strutsdata where name='"+name+"' "; + System.out.println(sql); + PreparedStatement ps=con.prepareStatement(sql); + int deleteCount=ps.executeUpdate(); + if(deleteCount>0){ + System.out.println("delete success"); + } + else{ + System.out.println("Try again"); + } + return deleteCount; + } + public List listAllCustomers() throws Exception{ + List list= new ArrayList(); + sql="select * from strutsdata"; + Statement st=con.createStatement(); + ResultSet rs=st.executeQuery(sql); + while(rs.next()){ + + list.add(buildCustomer(rs.getString(1), rs.getString(2), rs.getString(3))); + } + return list; + + } + public Customer buildCustomer(String name,String email,String phone){ + Customer customer; + customer=new Customer(); + customer.setName(name); + customer.setEmail(email); + customer.setPhone(phone); + return customer; + + } +} diff --git a/StrutsValidation/src/org/abburi/practice/dto/Customer.java b/StrutsValidation/src/org/abburi/practice/dto/Customer.java new file mode 100644 index 0000000..1ec45ea --- /dev/null +++ b/StrutsValidation/src/org/abburi/practice/dto/Customer.java @@ -0,0 +1,30 @@ +package org.abburi.practice.dto; + +public class Customer { +private String name; +private String email; +private String phone; + +/*public String addCustomer(){ + return "success"; +}*/ +public String getName() { + return name; +} +public void setName(String name) { + this.name = name; +} +public String getEmail() { + return email; +} +public void setEmail(String email) { + this.email = email; +} +public String getPhone() { + return phone; +} +public void setPhone(String phone) { + this.phone = phone; +} + +} diff --git a/StrutsValidation/target/classes/ApplicationResources.properties b/StrutsValidation/target/classes/ApplicationResources.properties new file mode 100644 index 0000000..ea9d231 --- /dev/null +++ b/StrutsValidation/target/classes/ApplicationResources.properties @@ -0,0 +1,9 @@ +name= Name +email= Email +phone= Phone +label.add.customer=Add Customer +label.update.customer= Update Customer + +errors.invalid=${getText(fieldName)} is invalid. +errors.required=${getText(fieldName)} is required. +errors.number=${getText(fieldName)} must be a number. \ No newline at end of file diff --git a/StrutsValidation/target/classes/org/abburi/practice/action/DeleteCustomerAction.class b/StrutsValidation/target/classes/org/abburi/practice/action/DeleteCustomerAction.class new file mode 100644 index 0000000..fd0155b Binary files /dev/null and b/StrutsValidation/target/classes/org/abburi/practice/action/DeleteCustomerAction.class differ diff --git a/StrutsValidation/target/classes/org/abburi/practice/action/EditAction.class b/StrutsValidation/target/classes/org/abburi/practice/action/EditAction.class new file mode 100644 index 0000000..d8224a4 Binary files /dev/null and b/StrutsValidation/target/classes/org/abburi/practice/action/EditAction.class differ diff --git a/StrutsValidation/target/classes/org/abburi/practice/action/LoadCustomersAction.class b/StrutsValidation/target/classes/org/abburi/practice/action/LoadCustomersAction.class new file mode 100644 index 0000000..98c3472 Binary files /dev/null and b/StrutsValidation/target/classes/org/abburi/practice/action/LoadCustomersAction.class differ diff --git a/StrutsValidation/target/classes/org/abburi/practice/action/SaveAction-validation.xml b/StrutsValidation/target/classes/org/abburi/practice/action/SaveAction-validation.xml new file mode 100644 index 0000000..25eca45 --- /dev/null +++ b/StrutsValidation/target/classes/org/abburi/practice/action/SaveAction-validation.xml @@ -0,0 +1,24 @@ + + + + + + true + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StrutsValidation/target/classes/org/abburi/practice/action/SaveAction.class b/StrutsValidation/target/classes/org/abburi/practice/action/SaveAction.class new file mode 100644 index 0000000..c49a984 Binary files /dev/null and b/StrutsValidation/target/classes/org/abburi/practice/action/SaveAction.class differ diff --git a/StrutsValidation/target/classes/org/abburi/practice/action/UpdateCustomerAction-validation.xml b/StrutsValidation/target/classes/org/abburi/practice/action/UpdateCustomerAction-validation.xml new file mode 100644 index 0000000..25eca45 --- /dev/null +++ b/StrutsValidation/target/classes/org/abburi/practice/action/UpdateCustomerAction-validation.xml @@ -0,0 +1,24 @@ + + + + + + true + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StrutsValidation/target/classes/org/abburi/practice/action/UpdateCustomerAction.class b/StrutsValidation/target/classes/org/abburi/practice/action/UpdateCustomerAction.class new file mode 100644 index 0000000..b01c7a4 Binary files /dev/null and b/StrutsValidation/target/classes/org/abburi/practice/action/UpdateCustomerAction.class differ diff --git a/StrutsValidation/target/classes/org/abburi/practice/dao/CustomerDao.class b/StrutsValidation/target/classes/org/abburi/practice/dao/CustomerDao.class new file mode 100644 index 0000000..06d4dc0 Binary files /dev/null and b/StrutsValidation/target/classes/org/abburi/practice/dao/CustomerDao.class differ diff --git a/StrutsValidation/target/classes/org/abburi/practice/dto/Customer.class b/StrutsValidation/target/classes/org/abburi/practice/dto/Customer.class new file mode 100644 index 0000000..75f7f6e Binary files /dev/null and b/StrutsValidation/target/classes/org/abburi/practice/dto/Customer.class differ diff --git a/StrutsValidation/target/classes/struts.xml b/StrutsValidation/target/classes/struts.xml new file mode 100644 index 0000000..a513fbf --- /dev/null +++ b/StrutsValidation/target/classes/struts.xml @@ -0,0 +1,32 @@ + + + + + + + + + listCustomers + /index.jsp + + + /list.jsp + /error.jsp + + + listCustomers + /error.jsp + + + /edit.jsp + /error.jsp + + + listCustomers + /error.jsp + /edit.jsp + + + \ No newline at end of file diff --git a/StrutsValidation/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF b/StrutsValidation/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..9e36ccc --- /dev/null +++ b/StrutsValidation/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Built-By: ABBURI'S +Build-Jdk: 1.8.0_101 +Created-By: Maven Integration for Eclipse + diff --git a/StrutsValidation/target/m2e-wtp/web-resources/META-INF/maven/StrutsInterceptor/StrutsInterceptor/pom.properties b/StrutsValidation/target/m2e-wtp/web-resources/META-INF/maven/StrutsInterceptor/StrutsInterceptor/pom.properties new file mode 100644 index 0000000..d81db98 --- /dev/null +++ b/StrutsValidation/target/m2e-wtp/web-resources/META-INF/maven/StrutsInterceptor/StrutsInterceptor/pom.properties @@ -0,0 +1,7 @@ +#Generated by Maven Integration for Eclipse +#Mon Nov 14 12:57:26 EST 2016 +version=0.0.1-SNAPSHOT +groupId=StrutsInterceptor +m2e.projectName=StrutsValidation +m2e.projectLocation=C\:\\Users\\ABBURI'S\\workspace2\\StrutsValidation +artifactId=StrutsInterceptor diff --git a/StrutsValidation/target/m2e-wtp/web-resources/META-INF/maven/StrutsInterceptor/StrutsInterceptor/pom.xml b/StrutsValidation/target/m2e-wtp/web-resources/META-INF/maven/StrutsInterceptor/StrutsInterceptor/pom.xml new file mode 100644 index 0000000..2763c5a --- /dev/null +++ b/StrutsValidation/target/m2e-wtp/web-resources/META-INF/maven/StrutsInterceptor/StrutsInterceptor/pom.xml @@ -0,0 +1,42 @@ + + 4.0.0 + StrutsInterceptor + StrutsInterceptor + 0.0.1-SNAPSHOT + war + + src + + + src + + **/*.java + + + + + + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + + maven-war-plugin + 3.0.0 + + WebContent + + + + + + + org.apache.struts + struts2-core + 2.5.5 + + + \ No newline at end of file diff --git a/TutorialFinder/.classpath b/TutorialFinder/.classpath new file mode 100644 index 0000000..03a69c3 --- /dev/null +++ b/TutorialFinder/.classpath @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/TutorialFinder/.project b/TutorialFinder/.project new file mode 100644 index 0000000..8542873 --- /dev/null +++ b/TutorialFinder/.project @@ -0,0 +1,36 @@ + + + TutorialFinder + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/TutorialFinder/.settings/.jsdtscope b/TutorialFinder/.settings/.jsdtscope new file mode 100644 index 0000000..8438762 --- /dev/null +++ b/TutorialFinder/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/TutorialFinder/.settings/org.eclipse.jdt.core.prefs b/TutorialFinder/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/TutorialFinder/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/TutorialFinder/.settings/org.eclipse.wst.common.component b/TutorialFinder/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..73d3430 --- /dev/null +++ b/TutorialFinder/.settings/org.eclipse.wst.common.component @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/TutorialFinder/.settings/org.eclipse.wst.common.project.facet.core.xml b/TutorialFinder/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..a29995a --- /dev/null +++ b/TutorialFinder/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/TutorialFinder/.settings/org.eclipse.wst.jsdt.ui.superType.container b/TutorialFinder/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/TutorialFinder/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/TutorialFinder/.settings/org.eclipse.wst.jsdt.ui.superType.name b/TutorialFinder/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/TutorialFinder/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/TutorialFinder/build/classes/login.xml b/TutorialFinder/build/classes/login.xml new file mode 100644 index 0000000..55200ca --- /dev/null +++ b/TutorialFinder/build/classes/login.xml @@ -0,0 +1,13 @@ + + + + + + /searchForm.jsp + /login.jsp + /login.jsp + + + \ No newline at end of file diff --git a/TutorialFinder/build/classes/org/koushik/javabrains/action/LoginAction.class b/TutorialFinder/build/classes/org/koushik/javabrains/action/LoginAction.class new file mode 100644 index 0000000..8f6aa5d Binary files /dev/null and b/TutorialFinder/build/classes/org/koushik/javabrains/action/LoginAction.class differ diff --git a/TutorialFinder/build/classes/org/koushik/javabrains/action/TutorialAction.class b/TutorialFinder/build/classes/org/koushik/javabrains/action/TutorialAction.class new file mode 100644 index 0000000..efafb63 Binary files /dev/null and b/TutorialFinder/build/classes/org/koushik/javabrains/action/TutorialAction.class differ diff --git a/TutorialFinder/build/classes/org/koushik/javabrains/model/User.class b/TutorialFinder/build/classes/org/koushik/javabrains/model/User.class new file mode 100644 index 0000000..6e3f9ac Binary files /dev/null and b/TutorialFinder/build/classes/org/koushik/javabrains/model/User.class differ diff --git a/TutorialFinder/build/classes/org/koushik/javabrains/service/LoginService.class b/TutorialFinder/build/classes/org/koushik/javabrains/service/LoginService.class new file mode 100644 index 0000000..0944982 Binary files /dev/null and b/TutorialFinder/build/classes/org/koushik/javabrains/service/LoginService.class differ diff --git a/TutorialFinder/build/classes/org/koushik/javabrains/service/TutorialFinderService.class b/TutorialFinder/build/classes/org/koushik/javabrains/service/TutorialFinderService.class new file mode 100644 index 0000000..33f8b22 Binary files /dev/null and b/TutorialFinder/build/classes/org/koushik/javabrains/service/TutorialFinderService.class differ diff --git a/TutorialFinder/build/classes/struts.xml b/TutorialFinder/build/classes/struts.xml new file mode 100644 index 0000000..7ae8598 --- /dev/null +++ b/TutorialFinder/build/classes/struts.xml @@ -0,0 +1,20 @@ + + + + + + + /success.jsp + /error.jsp + + + + + + /search{1}.jsp + + + + \ No newline at end of file diff --git a/TutorialFinder/src/login.xml b/TutorialFinder/src/login.xml new file mode 100644 index 0000000..55200ca --- /dev/null +++ b/TutorialFinder/src/login.xml @@ -0,0 +1,13 @@ + + + + + + /searchForm.jsp + /login.jsp + /login.jsp + + + \ No newline at end of file diff --git a/TutorialFinder/src/org/koushik/javabrains/action/LoginAction.java b/TutorialFinder/src/org/koushik/javabrains/action/LoginAction.java new file mode 100644 index 0000000..61df0aa --- /dev/null +++ b/TutorialFinder/src/org/koushik/javabrains/action/LoginAction.java @@ -0,0 +1,43 @@ +package org.koushik.javabrains.action; + +import org.apache.commons.lang3.StringUtils; +import org.koushik.javabrains.model.User; +import org.koushik.javabrains.service.LoginService; + +import com.opensymphony.xwork2.ActionSupport; +import com.opensymphony.xwork2.ModelDriven; + + +@SuppressWarnings({ "serial" }) +public class LoginAction extends ActionSupport implements ModelDriven { + private User user= new User(); + public User getUser() { + return user; + } + public void setUser(User user) { + this.user = user; + } + + public void validate(){ + if(StringUtils.isEmpty(user.getUserId())){ + addFieldError("userId", "UserID cannot be blank"); + } + if(StringUtils.isEmpty(user.getPassword())){ + addFieldError("password", "password cannot be blank"); + } + } + public String execute(){ + LoginService loginService = new LoginService(); + if (loginService.verifyLogin(user)){ + return SUCCESS; + } + return LOGIN; + } + @Override + public User getModel() { + // TODO Auto-generated method stub + return user; + } + + +} diff --git a/TutorialFinder/src/org/koushik/javabrains/action/TutorialAction.java b/TutorialFinder/src/org/koushik/javabrains/action/TutorialAction.java new file mode 100644 index 0000000..f26a7c4 --- /dev/null +++ b/TutorialFinder/src/org/koushik/javabrains/action/TutorialAction.java @@ -0,0 +1,40 @@ +package org.koushik.javabrains.action; + +public class TutorialAction { +private String language; +private String bestTutorialSite ; + +public String getBestTutorialSite() { + return bestTutorialSite; + +} + +public void setBestTutorialSite(String bestTutorialSite) { + this.bestTutorialSite = bestTutorialSite; +} +public String getTutorial() { + +//TutorialFinderService tutorialFinderService = new TutorialFinderService(); +//System.out.println(getLanguage()); +//setBestTutorialSite(tutorialFinderService.getBestTutorialSite(getLanguage())); + System.out.println("getTutorial() method called"); +return "success"; +} +public String addTutorial() { + +//TutorialFinderService tutorialFinderService = new TutorialFinderService(); +//System.out.println(getLanguage()); +//setBestTutorialSite(tutorialFinderService.getBestTutorialSite(getLanguage())); + System.out.println("addTutorial() method called"); + return "success"; + +} + +public String getLanguage() { + return language; +} + +public void setLanguage(String language) { + this.language = language; +} +} diff --git a/TutorialFinder/src/org/koushik/javabrains/model/User.java b/TutorialFinder/src/org/koushik/javabrains/model/User.java new file mode 100644 index 0000000..59adc30 --- /dev/null +++ b/TutorialFinder/src/org/koushik/javabrains/model/User.java @@ -0,0 +1,20 @@ +package org.koushik.javabrains.model; + +public class User { +private String userId; +private String password; + +public String getUserId() { + return userId; +} +public void setUserId(String userId) { + this.userId = userId; +} +public String getPassword() { + return password; +} +public void setPassword(String password) { + this.password = password; +} + +} diff --git a/TutorialFinder/src/org/koushik/javabrains/service/LoginService.java b/TutorialFinder/src/org/koushik/javabrains/service/LoginService.java new file mode 100644 index 0000000..1ee5111 --- /dev/null +++ b/TutorialFinder/src/org/koushik/javabrains/service/LoginService.java @@ -0,0 +1,14 @@ +package org.koushik.javabrains.service; + +import org.koushik.javabrains.model.User; + +public class LoginService { + public boolean verifyLogin(User user){ + if(user.getUserId().equals("userId") && user.getPassword().equals("password")){ + return true; + } + return false; + + } +} + diff --git a/TutorialFinder/src/org/koushik/javabrains/service/TutorialFinderService.java b/TutorialFinder/src/org/koushik/javabrains/service/TutorialFinderService.java new file mode 100644 index 0000000..1a90a3e --- /dev/null +++ b/TutorialFinder/src/org/koushik/javabrains/service/TutorialFinderService.java @@ -0,0 +1,11 @@ +package org.koushik.javabrains.service; + +public class TutorialFinderService { +public String getBestTutorialSite(String language) { + if (language.equals("java")){ + return "Java Brains"; } + else{ + return "Language not supported yet!"; +} +} +} \ No newline at end of file diff --git a/TutorialFinder/src/struts.xml b/TutorialFinder/src/struts.xml new file mode 100644 index 0000000..7ae8598 --- /dev/null +++ b/TutorialFinder/src/struts.xml @@ -0,0 +1,20 @@ + + + + + + + /success.jsp + /error.jsp + + + + + + /search{1}.jsp + + + + \ No newline at end of file diff --git a/TutorialFinder/web/META-INF/MANIFEST.MF b/TutorialFinder/web/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/TutorialFinder/web/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/TutorialFinder/web/WEB-INF/lib/commons-fileupload-1.3.2.jar b/TutorialFinder/web/WEB-INF/lib/commons-fileupload-1.3.2.jar new file mode 100644 index 0000000..4975590 Binary files /dev/null and b/TutorialFinder/web/WEB-INF/lib/commons-fileupload-1.3.2.jar differ diff --git a/TutorialFinder/web/WEB-INF/lib/commons-io-2.2.jar b/TutorialFinder/web/WEB-INF/lib/commons-io-2.2.jar new file mode 100644 index 0000000..84ca565 Binary files /dev/null and b/TutorialFinder/web/WEB-INF/lib/commons-io-2.2.jar differ diff --git a/TutorialFinder/web/WEB-INF/lib/commons-lang-2.4.jar b/TutorialFinder/web/WEB-INF/lib/commons-lang-2.4.jar new file mode 100644 index 0000000..532939e Binary files /dev/null and b/TutorialFinder/web/WEB-INF/lib/commons-lang-2.4.jar differ diff --git a/TutorialFinder/web/WEB-INF/lib/commons-lang3-3.2.jar b/TutorialFinder/web/WEB-INF/lib/commons-lang3-3.2.jar new file mode 100644 index 0000000..a30d272 Binary files /dev/null and b/TutorialFinder/web/WEB-INF/lib/commons-lang3-3.2.jar differ diff --git a/TutorialFinder/web/WEB-INF/lib/commons-logging-1.1.3.jar b/TutorialFinder/web/WEB-INF/lib/commons-logging-1.1.3.jar new file mode 100644 index 0000000..ab51254 Binary files /dev/null and b/TutorialFinder/web/WEB-INF/lib/commons-logging-1.1.3.jar differ diff --git a/TutorialFinder/web/WEB-INF/lib/freemarker-2.3.22.jar b/TutorialFinder/web/WEB-INF/lib/freemarker-2.3.22.jar new file mode 100644 index 0000000..a67a1c1 Binary files /dev/null and b/TutorialFinder/web/WEB-INF/lib/freemarker-2.3.22.jar differ diff --git a/TutorialFinder/web/WEB-INF/lib/javassist-3.11.0.GA.jar b/TutorialFinder/web/WEB-INF/lib/javassist-3.11.0.GA.jar new file mode 100644 index 0000000..b3bfeeb Binary files /dev/null and b/TutorialFinder/web/WEB-INF/lib/javassist-3.11.0.GA.jar differ diff --git a/TutorialFinder/web/WEB-INF/lib/ognl-3.0.19.jar b/TutorialFinder/web/WEB-INF/lib/ognl-3.0.19.jar new file mode 100644 index 0000000..8f31612 Binary files /dev/null and b/TutorialFinder/web/WEB-INF/lib/ognl-3.0.19.jar differ diff --git a/TutorialFinder/web/WEB-INF/lib/struts2-core-2.1.6.jar b/TutorialFinder/web/WEB-INF/lib/struts2-core-2.1.6.jar new file mode 100644 index 0000000..e509e97 Binary files /dev/null and b/TutorialFinder/web/WEB-INF/lib/struts2-core-2.1.6.jar differ diff --git a/TutorialFinder/web/WEB-INF/lib/xwork-core-2.1.6.jar b/TutorialFinder/web/WEB-INF/lib/xwork-core-2.1.6.jar new file mode 100644 index 0000000..bd5996b Binary files /dev/null and b/TutorialFinder/web/WEB-INF/lib/xwork-core-2.1.6.jar differ diff --git a/TutorialFinder/web/WEB-INF/lib/xwork2.jar b/TutorialFinder/web/WEB-INF/lib/xwork2.jar new file mode 100644 index 0000000..a7d763d Binary files /dev/null and b/TutorialFinder/web/WEB-INF/lib/xwork2.jar differ diff --git a/TutorialFinder/web/WEB-INF/web.xml b/TutorialFinder/web/WEB-INF/web.xml new file mode 100644 index 0000000..0665f41 --- /dev/null +++ b/TutorialFinder/web/WEB-INF/web.xml @@ -0,0 +1,15 @@ + + + TutorialFinder + + login.jsp + + + struts2 + org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter + + + struts2 + /* + + \ No newline at end of file diff --git a/TutorialFinder/web/login.jsp b/TutorialFinder/web/login.jsp new file mode 100644 index 0000000..739ffb8 --- /dev/null +++ b/TutorialFinder/web/login.jsp @@ -0,0 +1,17 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@taglib prefix="s" uri="/struts-tags"%> + + + + +Login + + + + + + + + + \ No newline at end of file diff --git a/TutorialFinder/web/searchForm.jsp b/TutorialFinder/web/searchForm.jsp new file mode 100644 index 0000000..8a20683 --- /dev/null +++ b/TutorialFinder/web/searchForm.jsp @@ -0,0 +1,16 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + <%@taglib prefix="s" uri="/struts-tags"%> + + + + +Search + + + + + + + + \ No newline at end of file diff --git a/TutorialFinder/web/searchTutorial.jsp b/TutorialFinder/web/searchTutorial.jsp new file mode 100644 index 0000000..a9130c3 --- /dev/null +++ b/TutorialFinder/web/searchTutorial.jsp @@ -0,0 +1,12 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +SearchTutorial + + +hello welcome to tutorial! + + \ No newline at end of file diff --git a/TutorialFinder/web/success.jsp b/TutorialFinder/web/success.jsp new file mode 100644 index 0000000..c23a715 --- /dev/null +++ b/TutorialFinder/web/success.jsp @@ -0,0 +1,13 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@taglib prefix="s" uri="/struts-tags" %> + + + + +success + + + + + \ No newline at end of file diff --git a/messenger/.classpath b/messenger/.classpath new file mode 100644 index 0000000..ddcb480 --- /dev/null +++ b/messenger/.classpath @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/messenger/.project b/messenger/.project new file mode 100644 index 0000000..a70e7c5 --- /dev/null +++ b/messenger/.project @@ -0,0 +1,42 @@ + + + messenger + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/messenger/.settings/.jsdtscope b/messenger/.settings/.jsdtscope new file mode 100644 index 0000000..2418123 --- /dev/null +++ b/messenger/.settings/.jsdtscope @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/messenger/.settings/org.eclipse.core.resources.prefs b/messenger/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..abdea9a --- /dev/null +++ b/messenger/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding/=UTF-8 diff --git a/messenger/.settings/org.eclipse.jdt.core.prefs b/messenger/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..443e085 --- /dev/null +++ b/messenger/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/messenger/.settings/org.eclipse.m2e.core.prefs b/messenger/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/messenger/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/messenger/.settings/org.eclipse.wst.common.component b/messenger/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..a1949f0 --- /dev/null +++ b/messenger/.settings/org.eclipse.wst.common.component @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/messenger/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml b/messenger/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml new file mode 100644 index 0000000..cc81385 --- /dev/null +++ b/messenger/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/messenger/.settings/org.eclipse.wst.common.project.facet.core.xml b/messenger/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..2dcd63f --- /dev/null +++ b/messenger/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/messenger/.settings/org.eclipse.wst.jsdt.ui.superType.container b/messenger/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/messenger/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/messenger/.settings/org.eclipse.wst.jsdt.ui.superType.name b/messenger/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/messenger/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/messenger/.settings/org.eclipse.wst.validation.prefs b/messenger/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..04cad8c --- /dev/null +++ b/messenger/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/messenger/pom.xml b/messenger/pom.xml new file mode 100644 index 0000000..13039b6 --- /dev/null +++ b/messenger/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + + org.chandra.java + messenger + war + 0.0.1-SNAPSHOT + messenger + + + messenger + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5.1 + true + + 1.7 + 1.7 + + + + + + + + + org.glassfish.jersey + jersey-bom + ${jersey.version} + pom + import + + + + + + + org.glassfish.jersey.containers + jersey-container-servlet-core + + + + + + org.glassfish.jersey.media + jersey-media-moxy + + + + + 2.16 + UTF-8 + + diff --git a/messenger/src/main/java/org/chandra/java/messenger/MyResource.java b/messenger/src/main/java/org/chandra/java/messenger/MyResource.java new file mode 100644 index 0000000..0a27d60 --- /dev/null +++ b/messenger/src/main/java/org/chandra/java/messenger/MyResource.java @@ -0,0 +1,25 @@ +package org.chandra.java.messenger; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +/** + * Root resource (exposed at "myresource" path) + */ +@Path("myresource") +public class MyResource { + + /** + * Method handling HTTP GET requests. The returned object will be sent + * to the client as "text/plain" media type. + * + * @return String that will be returned as a text/plain response. + */ + @GET + @Produces(MediaType.TEXT_PLAIN) + public String getIt() { + return "Got it!"; + } +} diff --git a/messenger/src/main/java/org/chandra/java/messenger/database/DatabaseClass.java b/messenger/src/main/java/org/chandra/java/messenger/database/DatabaseClass.java new file mode 100644 index 0000000..5bd6347 --- /dev/null +++ b/messenger/src/main/java/org/chandra/java/messenger/database/DatabaseClass.java @@ -0,0 +1,23 @@ +package org.chandra.java.messenger.database; + +import java.util.HashMap; +import java.util.Map; + +import org.chandra.java.messenger.model.Message; +import org.chandra.java.messenger.model.Profile; + +public class DatabaseClass { + + private static Map messages = new HashMap<>(); + private static Map profiles = new HashMap<>(); + + + public static Map getMessages(){ + return messages; + } + public static Map getProfiles(){ + return profiles; + } + + +} diff --git a/messenger/src/main/java/org/chandra/java/messenger/model/Comment.java b/messenger/src/main/java/org/chandra/java/messenger/model/Comment.java new file mode 100644 index 0000000..d999843 --- /dev/null +++ b/messenger/src/main/java/org/chandra/java/messenger/model/Comment.java @@ -0,0 +1,47 @@ +package org.chandra.java.messenger.model; + +import java.util.Date; + +public class Comment { + + + private long id; + private String message; + private Date created; + private String author; + + public Comment() { + + } + public Comment(long id, String message, String author) { + this.id = id; + this.message = message; + this.author = author; + this.created= new Date(); + } + + public long getId() { + return id; + } + public void setId(long id) { + this.id = id; + } + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } + public Date getCreated() { + return created; + } + public void setCreated(Date created) { + this.created = created; + } + public String getAuthor() { + return author; + } + public void setAuthor(String author) { + this.author = author; + } +} diff --git a/messenger/src/main/java/org/chandra/java/messenger/model/Message.java b/messenger/src/main/java/org/chandra/java/messenger/model/Message.java new file mode 100644 index 0000000..c0685ab --- /dev/null +++ b/messenger/src/main/java/org/chandra/java/messenger/model/Message.java @@ -0,0 +1,60 @@ +package org.chandra.java.messenger.model; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; + +@XmlRootElement +public class Message { + + private long id; + private String message; + private Date created; + private String author; + private Map comments = new HashMap<>(); + + public Message(){ + + } + public Message(long id, String message, String author) { + this.id = id; + this.message = message; + this.created = new Date(); + this.author = author; + } + public long getId() { + return id; + } + public void setId(long id) { + this.id = id; + } + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } + public Date getCreated() { + return created; + } + public void setCreated(Date created) { + this.created = created; + } + public String getAuthor() { + return author; + } + public void setAuthor(String author) { + this.author = author; + } + @XmlTransient + public Map getComments() { + return comments; + } + public void setComments(Map comments) { + this.comments = comments; + } + +} diff --git a/messenger/src/main/java/org/chandra/java/messenger/model/Profile.java b/messenger/src/main/java/org/chandra/java/messenger/model/Profile.java new file mode 100644 index 0000000..3f85d88 --- /dev/null +++ b/messenger/src/main/java/org/chandra/java/messenger/model/Profile.java @@ -0,0 +1,57 @@ +package org.chandra.java.messenger.model; + +import java.util.Date; + +public class Profile{ + + private long id; + private String profileName; + private String firstName; + private String lastName; + private Date created; + + public Profile() { + + } + + + public Profile(long id, String profileName, String firstName, String lastName) { + this.id = id; + this.profileName = profileName; + this.firstName = firstName; + this.lastName = lastName; + } + + + public long getId() { + return id; + } + public void setId(long id) { + this.id = id; + } + public String getProfileName() { + return profileName; + } + public void setProfileName(String profileName) { + this.profileName = profileName; + } + public String getFirstName() { + return firstName; + } + public void setFirstName(String firstName) { + this.firstName = firstName; + } + public String getLastName() { + return lastName; + } + public void setLastName(String lastName) { + this.lastName = lastName; + } + public Date getCreated() { + return created; + } + public void setCreated(Date created) { + this.created = created; + } + +} diff --git a/messenger/src/main/java/org/chandra/java/messenger/resources/CommentResource.java b/messenger/src/main/java/org/chandra/java/messenger/resources/CommentResource.java new file mode 100644 index 0000000..c5bbaba --- /dev/null +++ b/messenger/src/main/java/org/chandra/java/messenger/resources/CommentResource.java @@ -0,0 +1,48 @@ +package org.chandra.java.messenger.resources; + +import java.util.List; + +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + +import org.chandra.java.messenger.model.Comment; +import org.chandra.java.messenger.service.CommentService; + +@Path("/") +public class CommentResource { + + private CommentService commentService= new CommentService(); + @GET + public List getAllComments(@PathParam("messageId") long messageId){ + return commentService.getAllComments(messageId); + } + @GET + @Path("/{commentId}") + public String test2(@PathParam("messageId") long messageId,@PathParam("commentId") long commentId){ + return "commentId:"+ commentId + "messageId:" + messageId; + } + @POST + public Comment addComment(@PathParam("messageId") long messageId, Comment comment){ + return commentService.addComment(messageId, comment); + } + @PUT + @Path("/{commentId}") + public Comment updateComment(@PathParam("messageId") long messageId,@PathParam("commentId") long id, Comment comment){ + comment.setId(id); + return commentService.updateComment(messageId, comment); + } + @DELETE + @Path("/{commentId}") + public void removeComment(@PathParam("messageId") long messageId, @PathParam("commentId") long commentId){ + commentService.removeComment(messageId, commentId); + } + @GET + @Path("/{commentId}") + public Comment getComment(@PathParam("messageId") long messageId, @PathParam("commentId") long commentId){ + return commentService.getComment(messageId, commentId); + } +} diff --git a/messenger/src/main/java/org/chandra/java/messenger/resources/InjectDemoResource.java b/messenger/src/main/java/org/chandra/java/messenger/resources/InjectDemoResource.java new file mode 100644 index 0000000..498c908 --- /dev/null +++ b/messenger/src/main/java/org/chandra/java/messenger/resources/InjectDemoResource.java @@ -0,0 +1,34 @@ +package org.chandra.java.messenger.resources; + +import javax.ws.rs.Consumes; +import javax.ws.rs.CookieParam; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.MatrixParam; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.UriInfo; + +@Path("/injectdemo") +@Consumes(MediaType.TEXT_PLAIN) +@Produces(MediaType.TEXT_PLAIN) +public class InjectDemoResource { + + @GET + @Path("/annotations") + public String getParmsUsingAnnotations(@MatrixParam("param") String matrixParam, + @HeaderParam("authSessionID") String header, + @CookieParam("name") String cookie){ + return "Matrix param:"+ matrixParam +"Header Param"+ header+ "cookie param:"+cookie; + } + @GET + @Path("context") + public String getParamsUsingContext(@Context UriInfo uriInfo, @Context HttpHeaders headers){ + String path= uriInfo.getAbsolutePath().toString(); + String header= headers.getCookies().toString(); + return "path:" + path+ "header"+ header ; + } +} diff --git a/messenger/src/main/java/org/chandra/java/messenger/resources/MessageFilterBean.java b/messenger/src/main/java/org/chandra/java/messenger/resources/MessageFilterBean.java new file mode 100644 index 0000000..d11f24f --- /dev/null +++ b/messenger/src/main/java/org/chandra/java/messenger/resources/MessageFilterBean.java @@ -0,0 +1,28 @@ +package org.chandra.java.messenger.resources; + +import javax.ws.rs.QueryParam; + +public class MessageFilterBean { + + private @QueryParam("year") int year; + private @QueryParam("start") int start; + private @QueryParam("size") int size; + public int getYear() { + return year; + } + public void setYear(int year) { + this.year = year; + } + public int getStart() { + return start; + } + public void setStart(int start) { + this.start = start; + } + public int getSize() { + return size; + } + public void setSize(int size) { + this.size = size; + } +} diff --git a/messenger/src/main/java/org/chandra/java/messenger/resources/MessageResource.java b/messenger/src/main/java/org/chandra/java/messenger/resources/MessageResource.java new file mode 100644 index 0000000..bc39f83 --- /dev/null +++ b/messenger/src/main/java/org/chandra/java/messenger/resources/MessageResource.java @@ -0,0 +1,60 @@ +package org.chandra.java.messenger.resources; + +import java.util.List; + +import javax.ws.rs.BeanParam; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.chandra.java.messenger.model.Message; +import org.chandra.java.messenger.service.MessageService; + +@Path("/messages") +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +public class MessageResource { + + MessageService messageService= new MessageService(); + + @GET + public List getMessages(@BeanParam MessageFilterBean filterBean){ + if(filterBean.getYear()>0){ + return messageService.getAllMessagesForYear(filterBean.getYear()); + } + if(filterBean.getStart()>=0 && filterBean.getSize() >0){ + return messageService.getAllMessagesPaginated(filterBean.getStart(), filterBean.getSize()); + } + return messageService.getAllMessages(); + } + @GET + @Path("/{messageId}") + public Message getMessage(@PathParam("messageId") long id ){ + return messageService.getMessages(id); + } + @POST + public Message addMessage(Message message){ + return messageService.addMessages(message); + } + @PUT + @Path("/{messageId}") + public Message updateMessage(@PathParam("messageId") long id, Message message){ + message.setId(id); + return messageService.updateMessages(message); + } + @DELETE + @Path("/{messageId}") + public void deleteMessage(@PathParam("messageId") long id){ + messageService.removeMessage(id); + } + @Path("/{messageId}/comments") + public CommentResource getCommentResource(){ + return new CommentResource(); + } +} diff --git a/messenger/src/main/java/org/chandra/java/messenger/resources/ProfileResource.java b/messenger/src/main/java/org/chandra/java/messenger/resources/ProfileResource.java new file mode 100644 index 0000000..d873724 --- /dev/null +++ b/messenger/src/main/java/org/chandra/java/messenger/resources/ProfileResource.java @@ -0,0 +1,49 @@ +package org.chandra.java.messenger.resources; + +import java.util.List; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.chandra.java.messenger.model.Profile; +import org.chandra.java.messenger.service.ProfileService; + +@Path("/profiles") +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +public class ProfileResource { + + private ProfileService profileService = new ProfileService(); + @GET + public List getProfile(){ + return profileService.getAllprofiles(); + } + @POST + public Profile addProfile(Profile profile){ + return profileService.addprofiles(profile); + } + @GET + @Path("/{profileName}") + public Profile getProfile(@PathParam("profileName") String profileName){ + return profileService.getProfile(profileName); + } + @PUT + @Path("/{profileName}") + public Profile updateProfile(@PathParam("profileName") String profileName, Profile profile){ + profile.setProfileName(profileName); + return profileService.updateProfiles(profile); + } + @DELETE + @Path("/{profileName}") + public void removeProfile(@PathParam("profileName") String profileName){ + profileService.removeprofile(profileName); + +} +} diff --git a/messenger/src/main/java/org/chandra/java/messenger/service/CommentService.java b/messenger/src/main/java/org/chandra/java/messenger/service/CommentService.java new file mode 100644 index 0000000..58c60eb --- /dev/null +++ b/messenger/src/main/java/org/chandra/java/messenger/service/CommentService.java @@ -0,0 +1,47 @@ +package org.chandra.java.messenger.service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.chandra.java.messenger.database.DatabaseClass; +import org.chandra.java.messenger.model.Comment; +import org.chandra.java.messenger.model.Message; + +public class CommentService { + + private Map messages = DatabaseClass.getMessages(); + + public List getAllComments(long messageId){ + Map comments = messages.get(messageId).getComments(); + return new ArrayList(comments.values()); + } + public Comment getComment(long messageId, long commentId){ + Map comments= messages.get(messageId).getComments(); + return comments.get(commentId); + } + public Comment addComment(long messageId, Comment comment){ + Map comments= messages.get(messageId).getComments(); + comment.setId(comments.size() + 1); + comments.put(comment.getId(), comment); + return comment; + + } + public Comment updateComment(long messageId, Comment comment){ + Map comments= messages.get(messageId).getComments(); + if(comment.getId()<=0){ + return null; + } + comments.put(comment.getId(), comment); + return comment; + } + public Comment removeComment(long messageId, long commentId){ + Map comments= messages.get(messageId).getComments(); + return comments.remove(commentId); + + } +} + + + + diff --git a/messenger/src/main/java/org/chandra/java/messenger/service/MessageService.java b/messenger/src/main/java/org/chandra/java/messenger/service/MessageService.java new file mode 100644 index 0000000..8bbef4d --- /dev/null +++ b/messenger/src/main/java/org/chandra/java/messenger/service/MessageService.java @@ -0,0 +1,62 @@ +package org.chandra.java.messenger.service; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; +import java.util.Map; + +import org.chandra.java.messenger.database.DatabaseClass; +import org.chandra.java.messenger.model.Message; + +public class MessageService { + + private Map messages = DatabaseClass.getMessages(); + public MessageService(){ + messages.put(1L, new Message(1,"hello world", "chandra")); + messages.put(2L, new Message(2,"hello jersey", "chandra")); + } + + public List getAllMessages(){ + return new ArrayList(messages.values()); + } + + public List getAllMessagesForYear(int year){ + List mesagesForYear = new ArrayList<>(); + Calendar cal= Calendar.getInstance(); + for(Message message : messages.values()){ + cal.setTime(message.getCreated()); + if(cal.get(Calendar.YEAR)== year){ + mesagesForYear.add(message); + } + } + return mesagesForYear; + } + public List getAllMessagesPaginated(int start, int size){ + ArrayList list= new ArrayList(messages.values()); + if(start + size >list.size()) return new ArrayList(); + return list.subList(start, start+size); + + } + + public Message getMessages(long id){ + return messages.get(id); + + } + public Message addMessages(Message message){ + message.setId(messages.size() + 1); + messages.put(message.getId(), message); + return message; + + } + public Message updateMessages(Message message){ + if(message.getId()<=0){ + return null; + } + messages.put(message.getId(), message); + return message; + } + public Message removeMessage(long id){ + return messages.remove(id); + + } +} diff --git a/messenger/src/main/java/org/chandra/java/messenger/service/ProfileService.java b/messenger/src/main/java/org/chandra/java/messenger/service/ProfileService.java new file mode 100644 index 0000000..c799baf --- /dev/null +++ b/messenger/src/main/java/org/chandra/java/messenger/service/ProfileService.java @@ -0,0 +1,41 @@ +package org.chandra.java.messenger.service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.chandra.java.messenger.database.DatabaseClass; +import org.chandra.java.messenger.model.Profile; + +public class ProfileService { + + private Map profiles = DatabaseClass.getProfiles(); + + public List getAllprofiles(){ + return new ArrayList(profiles.values()); + } + public Profile getProfile (String profileName){ + return profiles.get(profileName); + + } + public Profile addprofiles(Profile profile){ + profile.setId(profiles.size() + 1); + profiles.put(profile.getProfileName(), profile); + return profile; + + } + public ProfileService() { + profiles.put("chandra", new Profile(1L,"chandraab","chandra","abburi")); + } + public Profile updateProfiles(Profile profile){ + if(profile.getProfileName().isEmpty()){ + return null; + } + profiles.put(profile.getProfileName(), profile); + return profile; + } + public Profile removeprofile(String profileName){ + return profiles.remove(profileName); + + } +} diff --git a/messenger/src/main/webapp/WEB-INF/web.xml b/messenger/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..e0720e4 --- /dev/null +++ b/messenger/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,18 @@ + + + + + Jersey Web Application + org.glassfish.jersey.servlet.ServletContainer + + jersey.config.server.provider.packages + org.chandra.java.messenger + + 1 + + + Jersey Web Application + /webapi/* + + diff --git a/messenger/src/main/webapp/index.jsp b/messenger/src/main/webapp/index.jsp new file mode 100644 index 0000000..a064b45 --- /dev/null +++ b/messenger/src/main/webapp/index.jsp @@ -0,0 +1,8 @@ + + +

Jersey RESTful Web Application!

+

Jersey resource +

Visit Project Jersey website + for more information on Jersey! + + diff --git a/messenger/target/classes/org/chandra/java/messenger/MyResource.class b/messenger/target/classes/org/chandra/java/messenger/MyResource.class new file mode 100644 index 0000000..81b3419 Binary files /dev/null and b/messenger/target/classes/org/chandra/java/messenger/MyResource.class differ diff --git a/messenger/target/classes/org/chandra/java/messenger/database/DatabaseClass.class b/messenger/target/classes/org/chandra/java/messenger/database/DatabaseClass.class new file mode 100644 index 0000000..9cba46d Binary files /dev/null and b/messenger/target/classes/org/chandra/java/messenger/database/DatabaseClass.class differ diff --git a/messenger/target/classes/org/chandra/java/messenger/model/Comment.class b/messenger/target/classes/org/chandra/java/messenger/model/Comment.class new file mode 100644 index 0000000..e3e128f Binary files /dev/null and b/messenger/target/classes/org/chandra/java/messenger/model/Comment.class differ diff --git a/messenger/target/classes/org/chandra/java/messenger/model/Message.class b/messenger/target/classes/org/chandra/java/messenger/model/Message.class new file mode 100644 index 0000000..0e0cd6b Binary files /dev/null and b/messenger/target/classes/org/chandra/java/messenger/model/Message.class differ diff --git a/messenger/target/classes/org/chandra/java/messenger/model/Profile.class b/messenger/target/classes/org/chandra/java/messenger/model/Profile.class new file mode 100644 index 0000000..908dc3d Binary files /dev/null and b/messenger/target/classes/org/chandra/java/messenger/model/Profile.class differ diff --git a/messenger/target/classes/org/chandra/java/messenger/resources/CommentResource.class b/messenger/target/classes/org/chandra/java/messenger/resources/CommentResource.class new file mode 100644 index 0000000..cf64c4b Binary files /dev/null and b/messenger/target/classes/org/chandra/java/messenger/resources/CommentResource.class differ diff --git a/messenger/target/classes/org/chandra/java/messenger/resources/InjectDemoResource.class b/messenger/target/classes/org/chandra/java/messenger/resources/InjectDemoResource.class new file mode 100644 index 0000000..02a22ac Binary files /dev/null and b/messenger/target/classes/org/chandra/java/messenger/resources/InjectDemoResource.class differ diff --git a/messenger/target/classes/org/chandra/java/messenger/resources/MessageFilterBean.class b/messenger/target/classes/org/chandra/java/messenger/resources/MessageFilterBean.class new file mode 100644 index 0000000..2af772f Binary files /dev/null and b/messenger/target/classes/org/chandra/java/messenger/resources/MessageFilterBean.class differ diff --git a/messenger/target/classes/org/chandra/java/messenger/resources/MessageResource.class b/messenger/target/classes/org/chandra/java/messenger/resources/MessageResource.class new file mode 100644 index 0000000..a778788 Binary files /dev/null and b/messenger/target/classes/org/chandra/java/messenger/resources/MessageResource.class differ diff --git a/messenger/target/classes/org/chandra/java/messenger/resources/ProfileResource.class b/messenger/target/classes/org/chandra/java/messenger/resources/ProfileResource.class new file mode 100644 index 0000000..9de1562 Binary files /dev/null and b/messenger/target/classes/org/chandra/java/messenger/resources/ProfileResource.class differ diff --git a/messenger/target/classes/org/chandra/java/messenger/service/CommentService.class b/messenger/target/classes/org/chandra/java/messenger/service/CommentService.class new file mode 100644 index 0000000..1d15790 Binary files /dev/null and b/messenger/target/classes/org/chandra/java/messenger/service/CommentService.class differ diff --git a/messenger/target/classes/org/chandra/java/messenger/service/MessageService.class b/messenger/target/classes/org/chandra/java/messenger/service/MessageService.class new file mode 100644 index 0000000..bf3d68f Binary files /dev/null and b/messenger/target/classes/org/chandra/java/messenger/service/MessageService.class differ diff --git a/messenger/target/classes/org/chandra/java/messenger/service/ProfileService.class b/messenger/target/classes/org/chandra/java/messenger/service/ProfileService.class new file mode 100644 index 0000000..a48c6bc Binary files /dev/null and b/messenger/target/classes/org/chandra/java/messenger/service/ProfileService.class differ diff --git a/messenger/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF b/messenger/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..9e36ccc --- /dev/null +++ b/messenger/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +Built-By: ABBURI'S +Build-Jdk: 1.8.0_101 +Created-By: Maven Integration for Eclipse + diff --git a/messenger/target/m2e-wtp/web-resources/META-INF/maven/org.chandra.java/messenger/pom.properties b/messenger/target/m2e-wtp/web-resources/META-INF/maven/org.chandra.java/messenger/pom.properties new file mode 100644 index 0000000..c9343c2 --- /dev/null +++ b/messenger/target/m2e-wtp/web-resources/META-INF/maven/org.chandra.java/messenger/pom.properties @@ -0,0 +1,7 @@ +#Generated by Maven Integration for Eclipse +#Mon Nov 14 12:57:30 EST 2016 +version=0.0.1-SNAPSHOT +groupId=org.chandra.java +m2e.projectName=messenger +m2e.projectLocation=C\:\\Users\\ABBURI'S\\workspace2\\messenger +artifactId=messenger diff --git a/messenger/target/m2e-wtp/web-resources/META-INF/maven/org.chandra.java/messenger/pom.xml b/messenger/target/m2e-wtp/web-resources/META-INF/maven/org.chandra.java/messenger/pom.xml new file mode 100644 index 0000000..13039b6 --- /dev/null +++ b/messenger/target/m2e-wtp/web-resources/META-INF/maven/org.chandra.java/messenger/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + + org.chandra.java + messenger + war + 0.0.1-SNAPSHOT + messenger + + + messenger + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5.1 + true + + 1.7 + 1.7 + + + + + + + + + org.glassfish.jersey + jersey-bom + ${jersey.version} + pom + import + + + + + + + org.glassfish.jersey.containers + jersey-container-servlet-core + + + + + + org.glassfish.jersey.media + jersey-media-moxy + + + + + 2.16 + UTF-8 + +