NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
</plugin>
</plugins>

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>5.2.0.RELEASE</version>
<type>pom</type>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>

<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>

<!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0-alpha-1</version>
<scope>provided</scope>
</dependency>

</dependencies>

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

<servlet><servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class></servlet>

<servlet-mapping><servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern></servlet-mapping>
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=
spring-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
">

<context:component-scan base-package="mvcdemo.Controller"></context:component-scan>

<bean name="ivs" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"></property>
</bean>


</beans>

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
register.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@page isELIgnored ="false" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h2>Register page </h2>

<form:form action="store" method="post" modelAttribute="bean" >
Enter roll: <form:input path="roll"/><br/><br/>
Enter name: <form:input path="name"/><br/><br/>

<input type="submit" value="Register">
<br/>
<h2>${msg }</h2>
</form:form>
</body>
</html>
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
login.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@page isELIgnored="false" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<h2>${msg}</h2>
<body>
<h1>Login form</h1>
<form:form action="check" method="post" modelAttribute="bean">
Enter Roll:<form:input path="roll"/><br/>
Enter Name:<form:input path="name"/><br/>

<input type="submit" value="Login">
</form:form>
</body>
</html>

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
home.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@page isELIgnored="false" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h2>${msg}</h2>
<center>
<a href="register">Register</a>&nbsp;&nbsp;
<a href="display">Display</a>
<a href="login">logout</a>
</center>
</body>
</html>

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
display.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page isELIgnored="false" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<table border="2" width="100%">
<tr>
<th>Roll</th>
<th>Name</th>
<th>Update</th>
<th>Delete</th>
</tr>
<c:forEach items="${data}" var="tab">
<form action="edit" method="post" modelAttribute="bean">
<tr>
<td width="60" align="center"><input type="text" value="${tab.roll}" name="roll" readonly></td>
<td width="60" align="center"><input type="text" value="${tab.name}" name="name"></td>
<td width="60" align="center"><input type="submit" value="Update"></form></td>

<td width="60" align="center">
<form action= "delete" method="post" modelAttribute="bean">
<input type="hidden" value="${tab.roll}" name="roll">
<input type="submit" value="Delete">
</form>
</td>
</tr>

</c:forEach>

</table>
<h2>${msg }</h2>
</body>
</html>
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
ApplicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<bean name="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/student" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>

<bean name="jt" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="ds"/>
</bean>


<bean name="dao" class="mvcdemo.model.StudentDao">
<property name="jdbc" ref="jt"/>

</bean>
<bean name="info" class="mvcdemo.model.Student"/>
</beans>
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
model/Student.java(roll(int),name,flag(int))
model/StudentDao.java

package mvcdemo.model;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCallback;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.RowMapper;

import com.mysql.cj.protocol.Resultset;

public class StudentDao {

private JdbcTemplate jdbc;

public JdbcTemplate getJdbc() {
return jdbc;
}

public void setJdbc(JdbcTemplate jdbc) {
this.jdbc = jdbc;
}

public Boolean save(final Student s)
{
String str="insert into studentinfo values(?,?)";
return jdbc.execute(str,new PreparedStatementCallback<Boolean>() {

public Boolean doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {

ps.setInt(1, s.getRoll());
ps.setString(2, s.getName());

return ps.execute();
}

});
}

public List display()
{
final List list = new ArrayList();

String str = "select*from studentinfo";

jdbc.query(str, new ResultSetExtractor<Student>() {

public Student extractData(ResultSet rs) throws SQLException, DataAccessException {

while(rs.next())
{
Student obj=new Student();
obj.setRoll(rs.getInt(1));
obj.setName(rs.getString(2));

list.add(obj);
}
return null;
}

});
return list;


}

public List update(final Student s) {

String str ="update studentinfo set name=? where rollno=?";
jdbc.execute(str,new PreparedStatementCallback<Boolean>() {

public Boolean doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {

ps.setString(1, s.getName());
ps.setInt(2, s.getRoll());
return ps.execute();
}
});
List list = display();
return list;
}

public List delete(Student s) {
//hideen field
String str="delete from studentinfo where rollno = '"+s.getRoll()+"'";
jdbc.update(str);
List list = display();

return list;
}

public List login(Student s) {
final List list =new ArrayList();
String str="select rollno,name from studentinfo where rollno = '"+s.getRoll()+"' and name = '"+s.getName()+"'";
jdbc.query(str, new ResultSetExtractor<Student>() {

public Student extractData(ResultSet rs) throws SQLException, DataAccessException {
if(rs.next())
{
Student obj=new Student();
obj.setRoll(rs.getInt(1));
obj.setName(rs.getString(2));
list.add(obj);
}
return null;
}

});
return list;
}



}

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Controller/HomeController.java

package mvcdemo.Controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.tomcat.util.log.UserDataHelper.Mode;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import mvcdemo.model.Student;
import mvcdemo.model.StudentDao;

@Controller
public class Homecontroller {

private ClassPathXmlApplicationContext conn;
@RequestMapping("/login")
public String login(Model m)
{
conn = new ClassPathXmlApplicationContext("ApplicationContext.xml");
Student stud=(Student)conn.getBean("info");
m.addAttribute("bean",stud);
return "login";
}

@RequestMapping("/check")
public String check(@ModelAttribute("bean") Student s,Model m,HttpServletRequest request)
{
conn = new ClassPathXmlApplicationContext("ApplicationContext.xml");
StudentDao obj =(StudentDao)conn.getBean("dao");
List list = obj.login(s);
if(!list.isEmpty())
{
m.addAttribute("msg","welcome"+s.getName());
s.setFlag(1);
HttpSession session = request.getSession();
session.setAttribute("logindata", s);
return "home";
}
else {
m.addAttribute("msg","Incorrect username and password");
return "login";
}
}

// @RequestMapping("/home")
// public String view1()
// {
// return "home";
// }

@RequestMapping("/register")
public String view2(Model m)
{
conn = new ClassPathXmlApplicationContext("ApplicationContext.xml");
Student stud = (Student)conn.getBean("info");
m.addAttribute("bean",stud);
return "register";
}

@RequestMapping("/store")
public String view3(@ModelAttribute("bean") Student s,Model m)
{
conn = new ClassPathXmlApplicationContext("ApplicationContext.xml");
StudentDao obj =(StudentDao)conn.getBean("dao");
obj.save(s);
m.addAttribute("msg","Record insert successfully....");
return "register";
}

@RequestMapping("/display")
public String view4(Model m)
{
conn = new ClassPathXmlApplicationContext("ApplicationContext.xml");
StudentDao obj =(StudentDao)conn.getBean("dao");
List list = obj.display();
m.addAttribute("data",list);
return "display";
}

@RequestMapping("/edit")
public String view5(@ModelAttribute("bean") Student s,Model m)
{
conn = new ClassPathXmlApplicationContext("ApplicationContext.xml");
StudentDao obj =(StudentDao)conn.getBean("dao");
List list = obj.update(s);
m.addAttribute("data",list);
m.addAttribute("msg","record update successfully");
return "display";
}

@RequestMapping("/delete")
public String view6(@ModelAttribute("bean") Student s,Model m)
{
conn = new ClassPathXmlApplicationContext("ApplicationContext.xml");
StudentDao obj =(StudentDao)conn.getBean("dao");
List list = obj.delete(s);
m.addAttribute("msg","record deleteed successfully");
return "display";
}

@RequestMapping("/logout")
public String logout(HttpServletRequest request)
{
HttpSession session = request.getSession();
Student stud =(Student)session.getAttribute("logindata");
stud.setFlag(0);
return "login";


}
}

//SELECT Orders.OrderID, Customers.CustomerName
//FROM Orders
//INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.