View JSP code
<>
< id="viewbean" scope="page" class="imsi.ViewBean">
< name="viewbean" property="data" value="">
<>here we have results< /h3>
<><>
< name="viewbean" property="data">
<><>
<>it worked..!< /h3>
related JAVA class code(imsi.ViewBean.java)
private String data;
public String getData() {
return this.data;
}
public void setData(String data) {
DBConnection db = new DBConnection();
db.dbConnect();
ResultSet result = null;
result = db.execute("select * from `mod_im` where mobile_no='0714280979'");
try {
// for (int i = 1; result.getRow() < data="" border="'1'">";
this.data=this.data+"< bgcolor="'#8dc4fc'"><><> Mobile Number < /b>< /td>";
this.data=this.data+"<><> Old IMSI number < /b>< /td>";
this.data=this.data+"<><> New IMSI number < /b>< /td>";
this.data=this.data+"<><> IMSI changed by < /b>< /td>";
this.data=this.data+"<><> IMSI changed on < /b>< /td>";
this.data=this.data+"<><> Time changed < /b>< /td>< /tr>";
while (result.next()) {
this.data=this.data+"<><>";
for (int i = 1; i<7; data="this.data+result.getString(i)+"><>";
}
this.data=this.data+"< /tr>";
}
this.data=this.data+"< /table>";
} catch (SQLException ex) {
ex.printStackTrace();
}
System.out.print(this.data);
}
Monday, March 10, 2008
Print ResultSet in HTML
Monday, March 3, 2008
< jsp:getProperty>
Gets the value of a Bean property so that you can display it in a result page.
This element retrieves the value of a bean property, converts it to a string
, and inserts it into the output.
JSP Syntax
< name="beanInstanceName" property="propertyName">
Examples
< id="calendar" scope="page" class="employee.Calendar">
<>
Calendar of < name="calendar" property="username">
< /h2>
Description
You must create or locate a Bean instance with <> before you use
<>.
The <> tag gets a Bean property value using the property's get method,
converts the value of a Bean property to a String and stores it in the out object.
In JSP 1.0, <> has a few limitations you should be aware of:
* You cannot use <> to retrieve the values of an indexed property.
* You can use <> with JavaBeans components, but not with enterprise
beans.
Sunday, March 2, 2008
< jsp:setProperty>
Sets a property value or values in a Bean.
Examples
< jsp:setProperty name="mybean" property="*" />
< jsp:setProperty name="mybean" property="username" />
< jsp:setProperty name="mybean" property="username" value="Steve" />
Description
The < jsp:setProperty> tag sets the value of one or more properties in a JavaBean component,
using the Bean's set methods. You must use a < jsp:useBean> tag before you use
< jsp:setProperty>. The value of name in < jsp:setProperty> must match the value of id in
< jsp:useBean>.
With < jsp:setProperty>, you can set property values in several ways:
* By passing all of the values in the user's request (stored as parameters in the
request object) to matching properties in the Bean
* By passing a specific value in the request object to a matching property or a property
of a different name in the Bean
* By explicitly setting a Bean property to a value specified as a String or the result
of an expression
Attributes and Usage
* name="beanInstanceName"
The name of an instance of a Bean that has already been created or located with a
< jsp:useBean> tag. The value of name must match the value of id in < jsp:useBean>. The
< jsp:useBean> tag must appear before < jsp:setProperty> in the same JSP file.
* property="*"
Stores all of the values in the request object parameters (called request parameters) in
matching Bean properties. The property names in the Bean must match the request parameters.
The parameter names usually come from the elements of an HTML form, and the values come from
the data the user enters.
The values of the request parameters are always of type String. The String values are
converted to other data types so they can be stored in Bean properties. The allowed Bean
property types and their conversion methods are as follows...
boolean or Boolean--java.lang.Boolean.valueOf(String)
double or Double--java.lang.Double.valueOf(String)
integer or Integer--java.lang.Integer.valueOf(String)
**If a request parameter has an empty or null value, the corresponding Bean property is not
set. Likewise, if the Bean has a property that does not have a matching request parameter,
the property value is not set.
# property="propertyName" [ param="parameterName" ]
Sets one Bean property to the value of one request parameter. The request parameter can have
a different name than the Bean property, and if so, you must specify param. If the Bean
property and request parameter have the same name, you can omit param.
If the parameter has an empty or null value, the corresponding Bean property is not set.
You cannot use both the param and value attributes in a < jsp:setProperty> tag.
# property="propertyName" value="{ string | < %= expression %> }"
Sets one Bean property to a specific value. The value can be a String or an Expression. If
you use a String, it is converted to the Bean property's data type, according to the
conversion rules. If you use an expression, the data type of the
value of the expression must match the data type of the Bean property.
If the parameter has an empty or null value, the corresponding Bean property is not set.
You cannot use both the param and value attributes in a < jsp:setProperty> tag.
**The following snippet says "set the numberOfItems property to whatever the value of the
numItems request parameter is, if there is such a request parameter. Otherwise don't do
anything."
< jsp:setProperty name="orderBean"
property="numberOfItems"
param="numItems" />
If you omit both value and param, it is the same as if you supplied a param name that
matches the property name.
Click here for details from Sun
< jsp:useBean>
This action lets you load in a JavaBean to be used in the JSP page. It locates or instantiates a Bean with a specific name and scope.
< jsp:useBean id="t1" scope="session" class="session.Time" />
this is quit similar to..
Time t1 = new Time ();
more over this you can specify a scope attribute...
Examples
< jsp:useBean id="cart" scope="session" class="session.Carts" />
< jsp:setProperty name="cart" property="*" />
< jsp:useBean id="checking" scope="session" class="bank.Checking" >
< jsp:setProperty name="checking" property="balance" value="0.0" />
< /jsp:useBean>
Description
The < jsp:useBean> tag attempts to locates a Bean, or if the Bean does not exist,
instantiates it from a class or serialized template. To locate or instantiate the Bean,
< jsp:useBean> takes the following steps, in this order:
1. Attempts to locate a Bean with the scope and name you specify.
2. Defines an object reference variable with the name you specify.
3. If it finds the Bean, stores a reference to it in the variable. Gives the Bean you
specified type.
4. If it does not find the Bean, instantiates it from the class you specify, storing a
reference to it in the new variable.
5. If it has instantiated (rather than located) the Bean, and if it has body tags
(between < jsp:useBean> and < /jsp:useBean>), executes the body tags.
Attributes and Usage
* id="beanInstanceName"
Names a variable that identifies the Bean in the scope you specify. You can use the
variable name in expressions or scriptlets in the same JSP file.
The name is case sensitive and must conform to the naming conventions of the page
scripting language (if you use the Java programming language, the conventions in the Java
Language Specification). If the Bean has already been created by another < jsp:useBean> tag,
the value of id must match the value of id used in the original < jsp:useBean> tag.
* scope="page|request|session|application"
Defines a scope in which the Bean exists and the variable named in id is available.
The default value is page.
* class="package.class"
Instantiates a Bean from a class, using the new keyword and the class constructor. The
class must not be abstract and must have a public, no-argument constructor. The package and
class name are case sensitive.
* class="package.class" type="package.class"
The value of type can be the same as class, a superclass of class, or an interface
implemented by class.
***very important
Once you have a bean, you can modify its properties via jsp:setProperty.
Recall that with beans, when you say "this bean has a property of type 'X' called foo",
you really mean "this class has a method called getFoo that returns something of type X,
and another method called setFoo that takes an X as an argument."
**Note that you can either supply an explicit value, give a param attribute to say that the
value is derived from the named request parameter, or just list the property to indicate
that the value should be derived from the request parameter with the same name as the
property.
Click here for detail document from Sun
Wednesday, February 20, 2008
Uploading a file in JSP
uploadFile.html...........
< body>
< !-- some codes... -->
< method="post" action="upload.jsp" name="uploadForm" enctype="'multipart/form-data'">
< !-- please notice (ENCTYPE='multipart/form-data').... -->
< input name="uploadfile" type="file">
< p>
< input name="Submit" value="Upload" type="submit">
< input name="Reset" value="Reset" type="reset">
< input name="action" value="upload" type="hidden">
< /p>
< !-- some codes... -->
< /body>
upload.jsp.............
<%@ page import="java.io.*"%>
<% String contentType = request.getContentType(); if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while (totalBytesRead < byteread =" in.read(dataBytes," file =" new" savefile =" file.substring(file.indexOf(" filename="\" savefile =" saveFile.substring(0," savefile =" saveFile.substring(saveFile.lastIndexOf(" lastindex =" contentType.lastIndexOf(" boundary =" contentType.substring(lastIndex" pos =" file.indexOf(" filename="\" pos =" file.indexOf(" pos =" file.indexOf(" pos =" file.indexOf(" boundarylocation =" file.indexOf(boundary," startpos =" ((file.substring(0," endpos =" ((file.substring(0," filepath="session.getServletContext().getRealPath(" fileout =" new">
***important>>notice
request.getContentType()
request.getInputStream()
request.getContentLength()
Monday, February 18, 2008
Getting Client Info..
< body>
--some codes go here
Client computer details:
< br>< br>
< b>Ip address< /b>:
< br>
<%=request.getRemoteAddr()%>
< br>< br>
< b>Computer name< /b>:
< br>
<%=request.getRemoteHost()%>
< br>< br>
--some codes go here
< /body>
*****important>>notice
request.getRemoteAddr()
request.getRemoteAddr()
methods
Sending a mail....
(1)method-Using JSPs and Java Mail API
Code from SendMail.jsp
< id="sendMail" class="SendMailBean" scope="page">
<% String a = request.getParameter("p_from"); String b = request.getParameter("p_to"); String c = request.getParameter("p_cc"); String d = request.getParameter("p_subject"); String e = request.getParameter("p_message"); %>
< %= sendMail.send(a, b, c, d, e) %>
(2)method-Using the sendMail utility tag
Code from SendMail.jsp
...
<% //Read all inputs into local variables String from = request.getParameter("p_from"); String to = request.getParameter("p_to"); String cc = request.getParameter("p_cc"); String bcc = request.getParameter("p_bcc"); String subject = request.getParameter("p_subject"); String message = request.getParameter("p_message"); String smtpSvr = request.getParameter("p_smtpServer"); session.setAttribute("smtpServer",l_smtpSvr); %>
< %-- Use OC4J Jsp mail tag to send the mail --%>
< host="'<%="(String)session.getValue(">'
sender='<%=from%>'
recipient='<%=to%>'
cc='<%=cc%>'
bcc='<%=bcc%>'
subject='<%=subject%>'>
<%=message%>
< /mail:sendMail>
...
also try this Click
Creating & Processing a Form using JSP
lets build the 'HTML form' first..
***myform.jsp
< body>
---some other codes
< form action="myformconfirm.jsp" method="post">
Enter in a website name:< br>
< input type="text" name="website">< br>
< input type="submit" value="Submit this" name="submit" />
< /form>
---some other codes
< /body>
***myformconfirm.jsp <<<
< body>
Your info has been received:
< br>< br>
<%
String sName = request.getParameter("website");
out.print(sName);
%>
< /body>
***important>>
notice the use of request.getParameter() method..
Javabeans for JSP ans Scopes
special type of class that has a number of methods.
JSP page can call these methods..
Javabean could be used in another JSP page (promoting reuse).
__To use a Javabean in a JSP page use the following syntax:
< id = " ...." scope = "application" class = "com...">
** scopes:
page - valid until page completes.
request - bean instance lasts for the client request
session - bean lasts for the client session.
application - bean instance created and lasts until application ends.
more about scopes.....
Application scope
Application scope is the broadest scope and should only be used when necessary. You can
create objects bound at application level in JSPs that are not session-aware. You can also
use application-bound objects to share data among different sessions of the same
application. When you no longer need objects bound to an application, you should explicitly
remove them to free up memory resources.
Session scope
In my experience, session scope is more commonly used than application scope. Session scope
allows you to create and bind objects to a SESSION. You must create objects bound to the
session in session-aware JSPs and make them available to all JSPs and servlets in the same
session. Session scope is often used for managing security credentials and for managing
state among multiple pages. As with application scope,
objects bound to session scope should be explicitly removed when no longer needed.
Request scope
I use request scope most often for binding created objects. Objects created and bound to
request scope are available to pages in that same request. These objects are automatically
released from memory when request processing completes. This is advantageous because
explicit cleanup is not required and there is less risk of burdening the system with
needless memory consumption.
Page scope
You should use page scope for objects created only for the current page. Like request scope,
the page scope does not require explicit removal of created and bound objects. I rarely use
page scope in my JSP applications, but it is the
**Using JSP tags
There are five main tags:
1. Declaration tag
2. Expression tag
3. Directive tag
4. Scriptlet tag
5. Action tag
1*Declaration tag
<%! %>
*To declare variables or methods.
*Do not generate output so are used with JSP expressions or scriptlets.
eg:
<%!
private int counter = 0 ;
private String get Account ( int accountNo) ;
%>
2*Expression tag
<%= %>
*To embed any Java expression
*It is short for out.println()
*semicolon ( ; ) does not appear at the end of the code
eg;
<%= new java.util.Date() %>
3*Directive tag
<%@ directive ... %>
*To gives special information about the page to the JSP Engine
*three main types of directives:
1)page - processing information for this page.
2)Include - files to be included.
3)Tag library - tag library to be used in this page.
(1)Page directive--optional attributes that provide the
JSP Engine with special processing information
language--Which language the file uses-- <%@ page language = "java" %>
extends--Superclass used by the JSP engine for the translated Servlet.
< %@ page extends = "com.taglib... %>
import-- Import all the classes in a java package into the current JSP page.
This allows the JSP page to use other java classes.
<%@ page import = "java.util.*" %>
info-- Developer uses info attribute to add information/document for a page.
Typically used to add author,version,copyright and date info.
<%@ page info = "http://best-jsp.blogspot.com/,copyright 2008. " %>
(2)Include directive-to include contents of a file inside another
eg:
<%@ include file = "include/privacy.html" %>
or
<%@ include file = "navigation.jsp" %>
4*Scriptlet tag
<% ... %>
*to emmbed any valid Java code is called a Scriptlet
eg:
<%
String username = "BA is the Greatest !" ;
out.println ( username ) ;
%>
Sunday, February 17, 2008
doing jsp with 3 files
3 kind of pages
(1)index.jsp.............
<>
<>
< equiv="Content-Type" content="text/html; charset=UTF-8">
<>JSP Page< /title>
< /head>
<>
<>Entry Form..< /h2>< name=" Name Input Form" action="response.jsp">
Enter your name:
< type="text" name="name" value="">
< type="submit" value="OK">
< /form>
< /body>
< /html>
(2)responsing JSP file(response.jsp)
<>
<>
< equiv="Content-Type" content="text/html; charset=UTF-8">
<>JSP Page< /title>
< /head>
<>
< id="mybean" scope="session" class="org.me.hello.NameHandler">
< name="mybean" property="name">
<>Hello, !< /h2>
< /body>
< /html>
(3)
package org.me.hello;
public class NameHandler {
private String name;
public NameHandler(){
name = null;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
.......
ok Try with Netbeans6
first jsp
**JSP simply puts Java inside HTML pages.
You can take any existing HTML page and change
its extension to ".jsp" instead of ".html".
**what makes JSP useful is the ability to embed Java.
< HTML>
< BODY>
Hello! The time is now < %= new java.util.Date() %>
< /BODY>
< /HTML>
**The character sequences < %= and %> enclose Java expressions,
which are evaluated at run time.