0% found this document useful (0 votes)
44 views

Sowji 9490872901 Namnamaa9290143667 Daddy - 9441481845 Arunph: 09989291211 To-Do: 409pg Get Parameter

The document discusses various concepts related to Java servlets, JSP, portals, and Spring MVC. It includes code snippets for servlet programming, accessing request parameters and cookies, using RequestDispatcher, and JSP tag libraries and implicit objects. It also provides definitions and descriptions of key portal concepts like portlets, portlet lifecycle, and the portlet container.

Uploaded by

pavan_091
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Sowji 9490872901 Namnamaa9290143667 Daddy - 9441481845 Arunph: 09989291211 To-Do: 409pg Get Parameter

The document discusses various concepts related to Java servlets, JSP, portals, and Spring MVC. It includes code snippets for servlet programming, accessing request parameters and cookies, using RequestDispatcher, and JSP tag libraries and implicit objects. It also provides definitions and descriptions of key portal concepts like portlets, portlet lifecycle, and the portlet container.

Uploaded by

pavan_091
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

03100480000357345027

sowji 9490872901
namnamaa9290143667
daddy---9441481845
Arunph: 09989291211
To-do:
409pg
Get Parameter:
String [] sizes = request.getParameterValues (“sizes”);
for(int x=0; x < sizes. length ; x++)
{
out.println (“<br>sizes: “ + sizes[x]);
}

Servlet Code to Download file:

public class CodeReturn extends HttpServlet {


public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType(“application/jar”);
ServletContext ctx = getServletContext();
InputStream is = ctx.getResourceAsStream(“/bookCode.jar”);
int read = 0;
byte[] bytes = new byte[1024];
OutputStream os = response.getOutputStream();
while ((read = is.read(bytes)) != -1) {
os.write(bytes, 0, read);
}
os.fl ush();
os.close(); }
}

PrintWriter
PrintWriter writer = response.getWriter();
writer.println(“some text and HTML”);

OutputStream
ServletOutputStream out = response.getOutputStream();
out.write(aByteArray);

Redirect:
response.sendRedirect(“http://www.oreilly.com”);
RequestDispatcher
A request dispatch does the work on the ser ver side
RequestDispatcher view = request.getRequestDispatcher(“result.jsp”);
view.forward(request,response);

Access InitParam:
out.println(getServletConfig().getInitParameter(“adminEmail”));
doubt:pg151

The client’s platform and browser info


String client = request.getHeader(“User-Agent”);

The cookies associated with this request


Cookie[] cookies = request.getCookies();

The session associated with this client


HttpSession session = request.getSession();

The HTTP Method of the request InputStream


String theMethod = request.getMethod();

An input stream from


input = request.getInputStream();
Access Init param from web.xml file:
web.xml file

<init-param>
<param-name>adminEmail</param-name>
<param-value>[email protected]</param-value>
</init-param>
<init-param> <param-name>mainEmail</param-name>
<param-value>[email protected]</param-value>
</init-param>

in doget method

java.util.Enumeration e = getServletConfi g().getInitParameterNames(); while(e.hasMoreElements())


{ out.println(“<br>param name = “ + e.nextElement() + “<br>”); } out.println(“main email is “ + getServletConfi
g().getInitParameter(“mainEmail”)); out.println(“<br>”); out.println(“admin email is “ + getServletConfi
g().getInitParameter(“adminEmail”));

9373449490
00540A

Getting a RequestDispatcher from a ServletRequest


RequestDispatcher view = request.getRequestDispatcher(“result.jsp”);

Getting a RequestDispatcher from a ServletContext


RequestDispatcher view = getServletContext().getRequestDispatcher(“/result.jsp”);

Calling forward() on a RequestDispatcher


view.forward(request, response);

Chapter Conversational State:


Sending a session cookie in the RESPONSE:
HttpSession session = request.getSession();

Getting the session ID from the REQUEST:


HttpSession session = request.getSession();

Creating a new Cookie


Cookie cookie = new Cookie(“username”, name);

Setting how long a cookie will live on the client


cookie.setMaxAge(30*60);

Sending the cookie to the client


response.addCookie(cookie);

Getting the cookie(s) from the client request


Cookie[] cookies = request.getCookies();
for (int i = 0; i < cookies.length; i++)
{ Cookie cookie = cookies[i];
if (cookie.getName().equals(“username”))
{
String userName = cookie.getValue();
out.println(“Hello “ + userName); break;
}
}

JSP:

Examples using pageContext to get and set attributes


Overriding jspInit():
<%!
Public void jspInit() {

ServletConfig sConfig = getServletConfig();

String emailAddr = sConfig.getInitParameter(“email”);

ServletContext ctx = getServletContext();

ctx.setAttribute(“mail”, emailAddr);
}
%>

Setting a page-scoped attribute <% Float one = new Float(42.5); %> <%
pageContext.setAttribute(“foo”, one); %>

Getting a page-scoped attribute <%= pageContext.getAttribute(“foo”) %>

Using the pageContext to set a session-scoped attribute <% Float two = new Float(22.4); %> <
% pageContext.setAttribute(“foo”, two, PageContext.SESSION_SCOPE); %>

Using the pageContext to get a session-scoped attribute <%= pageContext.getAttribute(“foo”,


PageContext.SESSION_SCOPE) %> (Which is identical to: <%= session.getAttribute(“foo”)
%> )

Using the pageContext to get an application-scoped attribute


Email is: <%= pageContext.getAttribute(“mail”, PageContext.APPLICATION_SCOPE) %>

Within a JSP, the code above is identical to:


Email is: <%= application.getAttribute(“mail”) %>

Using the pageContext to fi nd an attribute when you don’t know the scope <%= pageContext.fi
ndAttribute(“foo”) %>

9372383171

stopServer.bat WebSphere_Portal

serverStatus.bat –all

Declare and initialize a bean attribute with <jsp:useBean>

<jsp:useBean id=”person” class=”foo.Person” scope=”request” />

Get a bean attribute’s property value with <jsp:getProperty>

<jsp:getProperty name=”person” property=”name” />

EL implicit objects:

Getting the “host” header:

Host is: ${header[“host”]}

Getting the HTTP request method:

Method is: ${requestScope.method}

Getting Cookies and init params

${ cookie.userName.value}

email is: ${ initParam.mainEmail}

DOUBTS IN PORTALS:

PORTAL CNFIG
PORTAL CONTEXT

UPLOADFILE

PG 175
28281732

SPRING CHAPTERS + 11.5.4


12.4.3(SPRING MVC)
DBT 12.6(CACHE)
.9440195087
Portal:
A portal is a collection of mini web applications, called portlets, which supports features
like personalization, content aggregation, authentication and customization. Portlets act
as windowed web applications within the portal and each window on a portal web page
(called portal page) represents a portlet

portlet:

A portlet is a pluggable user interface component which provides specific piece of


content, which could be a service or information from existing information systems.
The primary responsibility of a portlet is to generate markup fragment (like HTML, XML
and WML), which is then displayed on a portal page within a window, called a portlet
window

LIFECYCLE MANAGEMENT
The portlet container is responsible for invoking lifecycle methods on the portlet instances and providing
them with the required runtime environment. A portlet container is an extension to servlet container, that
is, it provides what a servlet container provides, and additionally manages the portlet instances. The
portlets access their runtime environment using PortletContext object (similar to ServletContext),
which allows portlets to share data with other portlets and Servlets in the same portlet application.

RVHMX-KTJ8P-X7K2G-PC2M2-M6D76

SRIK NUM:8886037777

HTTP://EICHELGARTENWEG2.BLOGSPOT.COM/2009/01/MYSQL-AND-
WEBSPHERE-APPLICATION-SERVER.HTML

HTTP://DEV.MYSQL.COM/DOC/REFMAN/5.0/EN/CONNECTOR-J-INSTALLING-
CLASSPATH.HTML

[email protected] 9958228258

You might also like