The Artima Developer Community
Sponsored Link

Java Answers Forum
how to use sessions

1 reply on 1 page. Most recent reply: Jul 28, 2008 12:53 AM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
sivan bar

Posts: 1
Nickname: siv
Registered: Jul, 2008

how to use sessions Posted: Jul 25, 2008 12:01 PM
Reply to this message Reply
Advertisement
hello,I am trying to build a web site ,the problem is I am very new at this .
I wish to build a page that get a file from the user and an answears to a few questions I ask.I have allready done it then affter reciveing that data i wish to go to anew page and allow the user to choose to algortimes he wish to run on the file .build that page also .
The problem is i need to keep assesion with the user so if he wish to run adiffrent algo on the file he upload he can do thiswithout uploading all the info again .
I have no idea how to do this ,can anyone help ?
here is the code so far
the upload page where the user enter is file an answear afew questions

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ page import="java.io.*" %>
<script type="text/javascript">
//validate header yes or no
function validateValueHeader(obj){
if(obj=="yes" || obj=="YES"|| obj=="no" || obj=="NO" ){
return true;
}else{
alert("This field is required,header answer must be yes or no");
obj="";
return false;
}
}
//validate percentages
function validateValuePercentage(obj){
/* if(obj.contains("-")){
alert("value must be positive between 0-100");
obj="";
return false;
}
if(obj.contains("+")){
alert("value must be between 0-100,no math sign requried");
obj="";
return false;
}*/
if( obj==""){
alert("This field is required,value must be between 0-100");
obj="";
return false;
}
return true;
}
//validate all inputs before submit
function validateValues(){
if( validateValuePercentage(document.myInput.percentage.value)==false){
return false;
}
if( validateValueHeader(document.myInput.hasHeader.value)==false){
return false;
}
if(document.myInput.split.value==""){
alert("This field is required,please fill in a split sign");
return false;
}

return true;
}

</script>


<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="keywords" content="The Java Clustering Libary, bioinformatics, microarray, clustering">
<title>Upload data</title>
<link href="default.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<!-- start header -->
<div id="header">
<p><h1>The Java Clustering Libary</h1></p>
</div>
<!-- end header -->
<!-- start page -->
<div id="page">
<div id="pagebg">
<!-- start content -->
<div id="content">
<div class="post">
<div><img src="images/img08.gif" alt="" width="466" height="152" /></div>
<h1 class="title">Upload the data you wish to analysis!</h1>
<div class="entry">
<p><strong>Choose the file you wish to work with! </strong></p>
<FORM ENCTYPE="multipart/form-data" action="startAnalysisOK.jsp" METHOD="post" name="myInput" ONSUBMIT="return validateValues()">
<INPUT TYPE="file" NAME="fileToUpload" id="fileToUpload"><BR>
<input type="text" id="filePath" hidden><br>
Do you have a header? answear yes or no<BR>
<input type="text" id="hasHeader" size="10" ><BR>
What is your sign for a bad or missing value?
example "NA",null,0,- ...(default sign is "")<BR>
<input type="text" id="sign" size="10"><BR>
What is the percentage of missing or bad values in a time series you wish for us to ignore?
please give your answear between 0-100 ,0 mean anlysis all the result in the time series,
100 means if all the results have bad values ignore this time series.<BR>
<input id="percentage" type="text" size="10" ><BR>
What is the sign you use to split between the time value and the cellLine?
for example "BT549-10" the cellline is BT549 ,the time is 10 and the sign is -.<BR>
<input type="text" id="split" size="10" ><BR>
Do you have delimitor in your file?
example "\t" (default delimitor is "")<BR>
<input type="text" id="delimitor" size="10">
<br>
<input type="reset" name="reset" value="reset">
<input type="submit" name="submit" value="submit">
</FORM>
</div>
</div>
</div>
<!-- end content -->
<!-- start sidebar -->
<div id="sidebar">
<ul>
<li>
<h2>Categories</h2>
<ul>
<li><a href="home.html">Home</a></li>
<li><U>Upload Data</U></li>
<li><a href="startAnalysis.jsp">Start Analysis</a></li>
<li><a href="termOfService.html">Term Of Service</a></li>
<li><a href="referncesAndThanks.html">Refernces and Thanks</a></li>
</ul>
</li>
<li>


</li>
</ul>
</div>
<!-- end sidebar -->
<div style="clear: both;">&nbsp;</div>
</div>
</div>
<!-- end page -->
</body>
</html>

after getting all that info I wish for the user to choose two algos here is the code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<script type="text/javascript">
/*function display deatials on distance methods*/
function displayDetailes(currValue)
{
lDetailsDisplay = document.getElementById("DetailsDisplay");
if (currValue=="EuclideanDistance"){
// Changin the value of the explanation element.
lDetailsDisplay.value = "Euclidean distance cacluate the shortest path between two points";
lDetailsDisplay.rows = "2";
lDetailsDisplay.cols = "60";
}else if (currValue == "areaCalculation"){
lDetailsDisplay.value = "The function cacluate area bonded between two time series: T vs C The method is recommended for short time series,the algorthm is from the article Significance analysis of microarray transcript levels in time seriesexperiments by Barbara Di Camillo, Gianna Toffolo, Sreekumaran K Nair,Laura J Greenlund and Claudio Cobelli";
lDetailsDisplay.rows = "5";
lDetailsDisplay.cols = "60";
}else if(currValue=="CityBlock"){
lDetailsDisplay.value ="The city-block distance, alternatively known as the Manhattan distance, is related to the Euclidean distance. Whereas the Euclidean distance corresponds to the length of the shortest path between two points, the city-block distance is the sum of distances along each dimension. As gene expression data tend to have missing values, we define the city-block distance as the sum of distances divided by the number of dimensions d =1/n*sum(i=1 to n)abs(Xi-Yi) . This is equal to the distance you would have to walk between two points in a city, where you have to walk along city blocks.Explanation was taken from The C Clustering library written by Michiel de Hoon, Seiya Imoto, Satoru Miyano. ";
lDetailsDisplay.rows = "5";
lDetailsDisplay.cols = "60";
}else if(currValue=="6"){
lDetailsDisplay.value ="The Spearman rank correlation is an example of a non-parametric similarity measure. It is useful because it is more robust against outliers than the Pearson correlation.To calculate the Spearman rank correlation, we replace each data value by their rank if we would order the data in each vector by their value. We then calculate the Pearson correlation between the two rank vectors instead of the data vectors. Weights cannot be suitably applied to the data if the Spearman rank correlation is used. As in the case of the Pearson correlation, we can define a distance measure corresponding to the Spearman rank correlation as dS= 1 - rS,where rS is the Spearman rank correlation.Explanation was taken from The C Clustering library written by Michiel de Hoon, Seiya Imoto, Satoru Miyano. " ;
lDetailsDisplay.rows = "5";
lDetailsDisplay.cols = "60";
}else if(currValue=="similarityBySplines"){
lDetailsDisplay.value ="The function cacluate a regression for two time series profiles together T vs C and a regression for each time series profiles separately then cacluate F and decide if there is been achange or not.The method (Method3) is recommended for long time series,the algorthm is from the article Significance analysis of microarray transcript levels in time series experiments by Barbara Di Camillo, Gianna Toffolo, Sreekumaran K Nair,Laura J Greenlund and Claudio Cobelli " ;
lDetailsDisplay.rows = "5";
lDetailsDisplay.cols = "60";
}else if(currValue=="uncenteredCorrelation"){
lDetailsDisplay.value ="This is the same as Pearson correlation cofficient,except that the sample means are set to zero(xm and ym). The distance corresponding to the uncentered correlation coeffcient is d=1-r (r is the uncentered correlation).The uncentered correlation coefficient lies between -1 and 1,the corresponding distance lies between 0 and 2.Note you way use this in cases such as gene expression data is given in log ratios,a log ratio equel zero means that the experimental manipulation did not affect the gene expression.Explanation was taken from The C Clustering library written by Michiel de Hoon, Seiya Imoto, Satoru Miyano. " ;
lDetailsDisplay.rows = "5";
lDetailsDisplay.cols = "60";
}else if(currValue=="pearsonDistance"){
lDetailsDisplay.value ="The Pearson correlation coefficient is defined as r =1/n*sum (i = 1 to n)((xi -xm)/ax)*((yi -ym)/ay) in which xm, ym are the sample mean of x and y respectively, and ax, ay are the sample standard deviation of x and y. The Pearson correlation coefficient is a measure for how well a straight line can be fitted to a scatterplot of x and y.By taking the value of the Pearson correlation, we find a number between zero and one. If the value is one or minues one, all the points in the scatter plot lie on a straight line with either a positive or a negative slope respectively . If the value is equal to zero, there is no correlation between x and y.The distance is defined as usual as dP = 1-r ,where r is the Pearson correlation coefficient.As the value of the Pearson correlation coefficient lies between 2 and 0, the corresponding distance lies between 0 and 2 as well. In the context of gene expression experiments, note that if the correlation is equal to one if the gene expression data of two genes/microarrays have a shape that is exactly the same if the correlation is equal to minues one the shape is exactly opposite.Note that the Pearson correlation automatically centers the data by subtracting the mean, and normalizes them by dividing by the standard deviation. While such normalization may be useful in some situations (e.g., when clustering gene expression levels directly instead of gene expression ratios), information is being lost in this step. In particular, the magnitude of changes in gene expression is being ignored.Explanation was taken from The C Clustering library written by Michiel de Hoon, Seiya Imoto, Satoru Miyano. " ;
lDetailsDisplay.rows = "5";
lDetailsDisplay.cols = "60";
}
check();
}
/*function display deatials on clustring methods*/
function displayClusteringDetailes(currValue)
{
lDetailsDisplay = document.getElementById("DetailsClusteringDisplay");
if (currValue=="hierarchicClustering"){
// Changin the value of the explanation element.
lDetailsDisplay.value = "Hierarchic clustering";
lDetailsDisplay.rows = "2";
lDetailsDisplay.cols = "60";
document.clusteringMethods.attrName== "Hierarchic clustering";
}else if (currValue=="2"){
// Changin the value of the explanation element.
lDetailsDisplay.value = "clustering";
lDetailsDisplay.rows = "2";
lDetailsDisplay.cols = "60";
}
check();
}

//function check the user enter all the data
function check(){
if( document.myalgo.distanceMethods.value==0 || document.myalgo.clusteringMethods.onchange.value==0){
return false;
}
return true;
}
</script>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="keywords" content="The Java Clustering Libary, bioinformatics, microarray, clustering">
<title>Start Analysis</title>
<link href="default.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<!-- start header -->
<div id="header">
<p><h1>The Java Clustering Libary</h1></p>
</div>
<!-- end header -->
<!-- start page -->
<div id="page">
<div id="pagebg">
<!-- start content -->
<div id="content">
<div class="post">
<div><img src="images/img08.gif" alt="" width="466" height="152" /></div>
<h1 class="title">Choose the right methods for you!</h1>
<div class="entry">
<p><strong>Choose the methods you wish to work with!</strong></p>
<BR>
<p><weak>Distance Methods:</weak></p>
<form action = "result.jsp" method = "post" name="myalgo" ONSUBMIT="return check()" >
<select id="distanceMethods" name = "distanceMethods" onchange="displayDetailes(this.value)" >
<option value="0" >Choose distance method</option>
<option value="pearsonDistance" >Pearson distance</option>
<option value="areaCalculation">Area calculation </option>
<option value="EuclideanDistance">Euclidean distance</option>
<option value="CityBlock">City block</option>
<option value="similarityBySplines">Similarity by splines</option>
<option value="spearmanRankCorrelationDistance">Spearman rank correlation distance</option>
<option value="uncenteredCorrelation">Pearson distance uncentered correlation</option>
</select>
<BR>
<textarea id = "DetailsDisplay" rowa = "1" cols="60"> </textarea>
<BR>
<p><weak>Clustering Methods:</weak></p>
<select id="clusteringMethods" name = "clusteringMethods" onchange="displayClusteringDetailes(this.value)" >
<option value="0">Choose clustering method</option>
<option value="hierarchicClustering">Hierarchic clustering</option>
<option value="2">cluster2</option>
</select>
<BR>
<textarea id = "DetailsClusteringDisplay" rowa = "1" cols="60"> </textarea>
<BR>
<input type = "submit" id="submit" name="submit" value="submit">
</FORM>
</div>
</div>
</div>
<!-- end content -->
<!-- start sidebar -->
<div id="sidebar">
<ul>
<li>
<h2>Categories</h2>
<ul>
<li><a href="home.html">Home</a></li>
<li><a href="Upload.jsp" >Upload Data</a></li>
<li><U>Start Analysis</U></li>
<li><a href="termOfService.html">Term Of Service</a></li>
<li><a href="referncesAndThanks.html">Refernces and Thanks</a></li>
</ul>
</li>
<li>


</li>
</ul>
</div>
<!-- end sidebar -->
<div style="clear: both;">&nbsp;</div>
</div>
</div>
<!-- end page -->
</body>
</html>


now the problem i wish to go to the result page an anlysis the data i got from those two pages .how do i get the info from the upload.jsp also to reach result.jsp ?

I what to let the user choose two new algos to work with
on the same info i got on the upload.jsp?

can someone help me ?with the result.jsp how can i pass all that info there.
this is the first web i ever written i am learing all on my on i have very little background so I need clear instrction. someone told me i can do this using session but i didnt mange to do this .
Thank you for all your help and soory for my spelling mistakes english is not my native language .


Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: how to use sessions Posted: Jul 28, 2008 12:53 AM
Reply to this message Reply
Firstly please format your code in the appropriate java or code tags with indentition.

Haven't done much web stuff and the little I have done involved Webframeworks such as Expresso and Wicket (I would highly recommend Wicket - kind of gets you closer to a Rich-Client type dev. scenario which is way easier than handling Sessions, etc).

Though from the little I have used JSPs in, I believe you pass info around via something like:

From your first page you would go:

session.setAttribute("myProperty", myObject);


Where session is inherited from extending the appropriate Servlet, and myObject can be a DTO carrying the info you need, in this case your results.

Then in your other jsp, to get the Object carrying your info, you simply do:

MyObject obj = session.getAttribute("myPropery");
//  Do stuff with myObj

Flat View: This topic has 1 reply on 1 page
Topic: how to write a messenger with using java? Previous Topic   Next Topic Topic: cannot find symbol?......wats happening???

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use