5
select - dynamic project Web c ontent - JSP, CSS, j ava scri pt, imag es startserver from window select the JSP file --> run on server URL has two parts - static and dynamic http://localhost:8080/FirstProject/FirstPage.jsp -----static-----------------------|--dynamic---| change the index.html to jsp page you want to display as first page --it should be changed in web.xml after change in web.xml - restart the server this will pick from web.xml to display the page input tag for inputs inside tag - we have attributes <input type="text"> end tage is not manadatory for input, bold, para, <br> - break tag <select> tag wll create empty drop down box <option> tag type of button- submit, reset, button to send the data from jsp servlets - is java class, it will read value from user or web browser, and it va lidate the data and it will pass the sl to database finally it redirect to next page depend on sql output URL mapping while creating servlets add servlets jar - servlet- api.jar eclipse create mapping in web.xml for all servlets logic for normal button has to written using javascript <form> tag --> will have configuration of which serlvet to be called when we cli ck submit button it has two attributes action - servlet name n method - which method in servlets

Notes for J2EE

Embed Size (px)

Citation preview

Page 1: Notes for J2EE

 

select - dynamic projectWeb content - JSP, CSS, java script, images

startserver from window

select the JSP file --> run on server

URL has two parts -static and dynamic

http://localhost:8080/FirstProject/FirstPage.jsp-----static-----------------------|--dynamic---|

change the index.html to jsp page you want to display as first page --it shouldbe changed inweb.xml

after change in web.xml - restart the server

this will pick from web.xml to display the page

input tag for inputs

inside tag - we have attributes<input type="text">

end tage is not manadatory for input, bold, para,

<br> - break tag

<select> tag wll create empty drop down box<option> tag

type of button- submit, reset, button

to send the data from jsp

servlets - is java class, it will read value from user or web browser, and it validate the dataand it will pass the sl to database

finally it redirect to next page depend on sql output

URL mapping while creating servlets

add servlets jar - servlet- api.jar

eclipse create mapping in web.xml for all servlets

logic for normal button has to written using javascript

<form> tag --> will have configuration of which serlvet to be called when we click submit button

it has two attributes action - servlet name n method - which method in servlets

Page 2: Notes for J2EE

 

servlets has two methodsdoget , dopost

<form action="Registration" method="get">

reset - refresh ur pagesubmit - to call serlvetsnormal - no defualt action

logic for servlets1. read data from jsp2. validate data3. if validation is successful, connect to database , execute operation  3.1. forward to next page4. if validation fails - dont connect to database - forward to error page5. close db connection

input value are not passed in url in postmax url length - 255

doget is faster in dopost

3306127.0.0.1root

tomcat - 8080mysql - 3306oracle - 1521

primary keynot nullAI - auto increment

usernameemailphnogender

CREATE TABLE `j2eedb`.`new_table` (  `Id` INT NOT NULL AUTO_INCREMENT,  `username` VARCHAR(45) NULL,  `email` VARCHAR(45) NULL,  `phnno` BIGINT NULL,  `gender` CHAR(1) NULL,  PRIMARY KEY (`Id`));

user_reg

Long phn= Long.parseLong(request.getParameter("phno"));

diff between parsing and casting

casting - changing the class type to another calssparsing means - value of class

type of statements- statement - to execute static query-prepared statement - to execute dynamic

Page 3: Notes for J2EE

 

-callable statement - to execute stored proceudres

stored procedure- to avoid compile time error in mysqlperformance issues

select - executequeryinsert update, delete alter - executeUpdate

UPDATE `j2eedb`.`user_reg` SET `gender`='f' WHERE `Id`='3';

it takes from url and pass to web.xmland servlet name

gives 404 error - page not found

ResultSet is a type of output from sql.

In jsp to read the values- use request.getattribute of keyname.

Scriplet - java in jsp

Three types -1. <% %> ---> normal scriplet tag--> to write any java logic

2. <%! %> ---> declarative tag --> to declare any variable in jsp

3. <%= %> ---> expression tag --> to display any output.

object class is super class of all classes

attributes to pass values (servlt to jsp)parameter to pass parameters from jsp to servlts

User user = (User) request.getAttribute("userObject");

keep all the class level as private.

we can access the private varialbes using gettr and setter

beforeName: <%= user.name %><br> aftrerName: <%= user.getName()%><br>

user.java is bean class - only atttribute and getter setters, constructors

bean class has access to jsp for get attributes

Use same name for the radio button to select one of the option else both will get selected

Page 4: Notes for J2EE

 

embed tag for the videoattribute autoplay to auto play the video as false to stop this autoplay option

commons.file.jarfileutils class

has lot of methods creating, deleting, copy, etc.

JSTL - java standard tag library - to avoid scriptlet

5types- core- format- sql- xml- functions

- add two jars1. jstl.jar2. standard.jar

- import particular tag

- to refer JSTL variables use ${varName}- to refer scriptlet variables use <%= varName %>

request - only in next jsp you can read - only for next immediate read - next page or next servlet

implicit objects in JSP - automatically avaialbe in your page, need not to create itrequestresponsesessionaplicationconfigoutpageContextpage

context information --> session is created for each usercontext for per aplication - application id, name, language,

CSS and Javascript --w3schools.cominside in head -css, javascript

import - top of jsp

link is tag to css in jsplink rel="stylesheet" href = " path"

Page 5: Notes for J2EE

 

p#btitle - will aplly to only this para

also we can define in jsp itself under head tag, stype tag

external css can be reused

control the behviour of screen. Click button..etc