I am getting user input by get method
out.print("<FORM METH0D=GET action =\"index.jsp\">");
out.print("<INPUT TYPE=TEXT NAME=searchTerm><BR><BR>");
and using request.getParameter() for getting value.
request.getParameter("searchTerm");
so, if request.getParameter() is null i hide some code of my page as you'll see . But although user not search any item and request.getParameter("searchTerm")is null.
this Portion of my page is not working....
String see ="null";// here is problem
String saw =(String) request.getParameter("searchTerm");
if(see.equalsIgnoreCase(saw))
{
out.println("get is false");
Get = false;}
else {
Get = true;
out.println("get is true now "+ request.getParameter("searchTerm"));
out.print("<br />");
}
Whole page code is here.... (no error)
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Collection"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.io.*" %>
<%@page import="java.net.URL" %>
<%@page import="java.net.URLEncoder" %>
<%@page import="java.net.URLConnection" %>
<%@page import="org.apache.regexp.*" %>
<%! String term=""; %>
<%! boolean Get = false; %>
<%
request.getParameter("searchTerm");
URL url = new
URL("http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?dispmax=10 &db=pubmed&cmd=search&term=" +
URLEncoder.encode(term, "UTF-8"));
URLConnection urlConnection = url.openConnection();
BufferedReader reader = new BufferedReader(new
InputStreamReader(urlConnection.getInputStream()));
String s = null;
RE pmidRE = new RE("PMID: ([0-9]+) \\[PubMed");
Collection pmids = new ArrayList();
while ((s = reader.readLine()) != null) {
if (pmidRE. match(s )) {
pmids.add(pmidRE.getParen(1));
}
}
reader.close();
String see ="null";// here is problem
String saw =(String) request.getParameter("searchTerm");
if(see.equalsIgnoreCase(saw))
{
out.println("get is false");
Get = false;}
else {
Get = true;
out.println("get is true now "+ request.getParameter("searchTerm"));
out.print("<br />");
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD><TITLE>PubMed Servlet 1.1</TITLE></HEAD>
<B0Dy>
<b>Java for Bioinformatics: </b>
<h1><font color=red><b>PubMed Servlet version
l.l</b></font></h1>
<%
if(Get== true)
{
out.print("<BR><br>PMIDs found:<br>\n");
int i =1;
for (Iterator iterator = pmids.iterator();
iterator.hasNext();) {
String si = (String) iterator.next();
out.print("<a href=\"");
out.print("http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=pubmed£idopt=Abstract&list_uids=") ;
out.print(si) ;
out.print("\">") ;
out.print(si) ;
out.print("</a>\n");
if (iterator.hasNext() && i++ != 5) {
out.print(" - ") ;
} else {
out.print("<BR>");
}
}
}
out.print("<br/> <br /><B>Please enter a term to search on NCBI<br /> PubMed:</B><BR><BR>" );
out.print("<FORM METH0D=GET action =\"index.jsp\">");
out.print("<INPUT TYPE=TEXT NAME=searchTerm><BR><BR>");
out.print("<INPUT TYPE=SUBMIT VALUE=Search PubMedX\"><BR>" );
out.print("</FORM> " );
out.print("</BODY>" );
out.print("</HTML>");
%>