Mehdi9721 / JAVAEE-DAC

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JAVAEE FROM CDAC

Cookie and Httpsession is important in terms of session managemnet, Cookie will help to identify client even after logoff from session, but seesion maintains current activity while client is connected with server.

Session

HttpSession session=req.getSession();

cookie

Cookie c= new Cookie("name"+,"value");
to access Cookie, we should store in an array and use foreach loop to getName() from cookies
Cookie[] c=req.getCookies();

started learning Spring

BEANS

beans definition should be written in cofiguration xml file

xml

the bean definition for XMl config

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns = "http://www.springframework.org/schema/beans"
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation = "http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
  <bean name="car" class="Car"></bean>
   </beans>
``````````````````````````````````````````````````````````````````````````````````````````
####annotation based
for annotation based we also need definition in xml

definition for xml annotation

<context:component-scan base-package="l"></context:component-scan>

Spring STS

STS-4 --> MAVEN project in Spring starter --> add tools of web and java ee from eclips marketplace in sts else jsp will not created --> add tomcat jasper in dependency for jsp to servlet

@SpringBootApplication

this annoted class is a main (Dispatcher servlet)
IT will look for Controller where we marked Controller to a class
and @RequestMapping("/") will map the required method and returns the view.jsp file

to add jpa file it should be added in

src-main-webapp-a.jsp

we can also give direction to view resolver for locating jsp file in Properties

JPA

set properties dialect

spring.datasource.url=jdbc:mysql://localhost:3306/testhibernate
spring.datasource.username=root
spring.datasource.password=8052608851
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=update

pom dependency

{


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.springframework.boot spring-boot-starter-parent 2.1.2.RELEASE

<groupId>com.example</groupId>
<artifactId>firstBootMVC</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>firstBootMVC</name>
<description>first project for Spring Boot</description>
<properties>
	<java.version>1.8</java.version>
</properties>
<dependencies>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-web</artifactId>
	</dependency>

	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-test</artifactId>
		<scope>test</scope>
	</dependency>
	<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-jasper -->
org.apache.tomcat tomcat-jasper 9.0.14 com.mysql mysql-connector-j 8.1.0
	<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
org.springframework.boot spring-boot-starter-data-jpa
</dependencies>

<build>
	<plugins>
		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
		</plugin>
	</plugins>
</build>
}

REST API

Add anotation as @ResponseBody which will let view know that ,Now he will convert response to json
use Optional (for handling null also)

About


Languages

Language:Java 95.4%Language:HTML 4.6%