Monday, March 10, 2008

Print ResultSet in HTML

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 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