Start from Java 5 -- JSP(haven't finished)
12 Apr 2017 | JavaClass notes
Java Server Pages(JSP)
- server side , java platform
- CGI
- Perl
- Servlets
- JSP: ont top of servlet, every JSP has servlet, technically
- other platforms: PHP, ASP.net
- Servlet: primary implementation in java platform to show html
- Web containers / web servers:
- Tomcat
- jetty
- apache
- JavaWebServer
- Application servers: - Enterprise Architecture
- JBoss
- WebLogic
- WebSphere
- Glassfish
- Oracle Java EE Server
- technical difference between 3, 4, 4, scalable, all can use 3, also can use 4. Some 3 can not handle, use 4
- all applications we run was desktop applications.
- a web proj:
- webContent
- *.html
- *.jsp
- style folder
- *.css
- script folder
- *.js
- images
- *.png…
- WEB-INF
- web.xml
- *.JAR
- classes folder
- *.class files of entire source files
- *.tld
- web.xml
- src
- all java source packages and files (*.java)
- Business layer files
- Controller classes
- service / DAO layer
- Servlets, are also called controller
- POJO / Model Objects / ORM (object oriented mapping)
- *.xml
- *.properties
- *.json
- all java source packages and files (*.java)
- pom.xml
- webContent
- Steps:
- download tomcat –> right click in eclipse –> other –> create server –> apache tomcate
- new web dynamic web prj –> set target runtime == tomcat –> do not finish directly, click next, next and check the box with generate web.xml
- check doPost or doGet depends on your demand in somewhere
- create index.html in WebContent folder: index.html it the file we gonna show/run. (this is set in web.xml, we can commit the files we do not need)
- never check box: always use this server
- Two ways :
- jsp: html with java embedded
- declaration tag, global variable, eg:
<head> <%! Connection con; %> </head>
- !
- only once
- must in <head></head>
- normal ??
<% ... %>
- expression
<%= aVariable %>
- declaration tag, global variable, eg:
- servlet, java html embedded, it has drawbacks, when we need complex html, so use jsp.
- jsp: html with java embedded
- login.jsp, we need:
- create profile
- session: destroy is not for session, is for jsp life cycle
- connection only once, so we do not implement this part of java in normal .., for initialization propose, we implement in jsp init
- jsp life cycle (3) ?? : jsp init, jsp execute, cleanup
- connect db, so need convert to maven
- we need : shift business logic in jsp to java class
- response.sendDirect(“index.html”). automatically redirect and send.
- session.removeAttribution(“name??”)..if(session,attr()==null) ?? logout, we have a new session with a new sessionId, When we do not use cookie.
- 4 scopes: request(default scope), page, session, application. request died, java object died, so if we remove scope = “session”, the counter is always 1
- if user login from different browser ==> we need a flag to mark if this user has logged in(or the new session replace the old session??)
-
useBean, setProperty associated with request, replace request.getParameter
- directive
- page
- import (when want to import in jsp, we need directive page)
- include
- taglib
- page
- action page
- use Bean
- setProperty
- getProperty
- forward
- include
- taglibs
- implicit object
- request
- response
- session
- out
- pageContent
Notes stopped here and I skipped Oracle part.
Question list
- Difference between handling checked exceptions and handling unchecked exceptions
- An Inner class defined within a method can access everything from outside the method but only final type of variables or objects from within the method in which it is defined.(wt??)
- no private static?
- only want 3 objs of a class
Comments