0

I'm creating an app, that displayes a String from a database. This String is then displayed in a textbox that cannot be edited.

I now require that varible (ID passed) in the text box to be compared with a column in a SQL database table which is an identical String. Once the matching String is found I need to update other columns based on the queries.

when i use request.getParameters() method it is giving output as null.

i need it to be done purely in jsp. please help.

Edited by sunnykeerthi

4
Contributors
7
Replies
11
Views
5 Years
Discussion Span
Last Post by subramanya.vl
0

I think we dont have any method like request.getParameters(). it is getParameter(). Show your code then only we can help

0

Hi,
i made it read only.
here the data is getting retrieved from a sql query and below is the code that i used to do so.

<%@page import="java.sql.*"%>  
<%@page import="java.lang.*"%>  
<%@page import="java.io.*"%>  
<%@page language="Java"%>  
<html>  
<head>  
<script type="text/javascript">  

function move(){  

 document.getElementById('tgt1').value = document.getElementById('Allocation').value;  
 document.getElementById('Allocation').value="";  
 document.getElementById("Send").disabled=true;  

}  
function UnBlock()  
{  
    document.getElementById("tgt1").value="";  
    document.getElementById("Send").disabled=false;  
    document.getElementById("tgt2").style.display="block";  
    document.getElementById("Query_but").style.display="block";  
   }  
function UnBlock_Only(){  

    document.getElementById("Send").disabled=false;  
    document.getElementById("Query").disabled=true;  
}  
function Alloc_Insert()  
{  
    document.myform.action="Alloc_Insert.jsp";  
    document.myform.method="post";  
    document.myform.submit();  
}  

</script>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
<style type="text/css">  
body {  
    margin-top: 20px;  
    margin-left: 30px;  

}  
</style>  
</head>  
<body>  

    <form name="myform" method="post" action="Alloc_Insert.jsp">  
<%  
try {  
    String sessname=(String)session.getAttribute("myusername");  
    PreparedStatement ps,ps2=null;  
    ResultSet rs=null;  
    Statement st=null;  
    Connection con=null;  
    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();  
    con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "tiger");  
    ps=con.prepareStatement("select DBID from Scope1 where specialist IS Null");  
    rs = ps.executeQuery();  
    if(rs.next())  
    {  
  %>  
<input type="text" name="Allocation" size="75" id="Allocation" value="<%=rs.getString("DBID")%>" readonly="readonly">  
<%  
}  
}  
catch(Exception e){  
out.println(e);  
}  
%>  


<a href="Alloc_Insert.jsp" value="Allocate" id="Send" name="Send" onclick="Clicked()">Allocate</a><br/>  
<br/><br/><br/><br/><br/><br/>  
<table>  
<tr>  
<input type="text" id="tgt1" size="100">  
<td><input type="button"value="Query" id="Query" onClic="UnBlock()"></td>  
<td><input type="button" value="Westlaw Verification" onClick="UnBlock_Only()"></td>  
</tr><br/>  
</table><textarea name="tgt2" id="tgt2" cols="30" rows="5" style="display:none"></textarea>  
<table><tr><td><a href="Insert.jsp" style="display: none" id="Query_but" onclick="Add_Query()">Submit Query</a></td></tr></table>  
<table><tr><td><input type="text" value="" id="demo" size="75"></td></tr></table>  
</form>  
 </body>  
</html> 

and the jsp used to compare the data is as below

<%@page import="java.sql.PreparedStatement"%>  
<%@page import="java.sql.DriverManager"%>  
<%@page import="java.sql.DriverManager"%>  
<%@page import="java.sql.Connection"%>  
<%@page import="java.sql.ResultSet"%>  
<%@page import="java.sql.ResultSet"%>  
<%@page import="java.lang.String"%>  
<html>  
    <head>  
    </head>  
    <body>  
<%   

     try{  
            ResultSet rs=null;  
            String Add=request.getParameter("Allocation.text");  
            String user=(String) session.getAttribute("myusername");  
            Class.forName("oracle.jdbc.driver.OracleDriver");  
            java.util.Date today = new java.util.Date();  
            java.sql.Timestamp t= new java.sql.Timestamp(today.getTime());  
            Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","tiger");  
            PreparedStatement ps=con.prepareStatement("Update Scope1 SET ALLOCATED=?, SPECIALIST=? WHERE DBID='"+Add+"'");  
            ps.setTimestamp(1, t);  
            ps.setString(2, user);  
            /*ps.setString(3, Add_U);*/  
            ps.executeUpdate();  
            out.println(user);  
            out.println(con);  
            out.println(t);  
            out.println(Add);  
            con.commit();  

             }  
        catch(Exception e)  
                       {  
            out.println(e);  
                       }  

%>  

    </body>  
</html>  
0

It sounds like you have problem with the this line

 String Add=request.getParameter("Allocation.text");

request.getParameter() Returns the value of the named attribute, It will return null if no attribute of the given name exists.i.e you cant access through the id

0

Hi Anand thanks for the previously, i am eager to know about how do i access the text in the textbox "Allocation" on my first jsp. the text over there is actually displayed from the database, but is not assigned to the textbox. how do i assign it to the textbox and use it to compare with the database.

0

you never combine the code of jsp with html componets

html component never communicate with jsp tags
jsp tags can't read html component values

but you are asking these two combination.

i think you got the point

Edited by radhakrishna.p: for clarity

0

@sunnykeerthi

request.getParameter("some_value") gets the value from "request parameter" and not "attribute".

Request parameters are sent as query string in a URL.

The code where data from database is populated ON first JSP is given below.

<input type="text" name="Allocation" size="75" id="Allocation" value="<%=rs.getString("DBID")%>" readonly="readonly"> 

I observe that this textbox is having only one id which is "Allocation" and this is same for all the data received from data base. If multiple values are received from database then there will be same number of text boxes and all of them have same id "Allocation" .
This is incorrect. Because on JSPs each element must have unique id.

I dont understand the need to put the value from resultset into a text-box.

This is ok if you are displaying it to a user.

If this(DBID) value needs to be sent to another page from current page.

Then construct a string by appending each value from result-set and send this as a "query string" to the next link(that is next jsp).

So in your code do like this on first JSP

String all_DBIDs="";// define a string to hold the values
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();  
    con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "tiger");  
    ps=con.prepareStatement("select DBID from Scope1 where specialist IS Null");  
    rs = ps.executeQuery();  
    if(rs.next())  
    {  
      all_DBIDs=all_DBIDs+rs.getString("DBID");// append values to string from DB;
  %>  
<input type="text" name="Allocation" size="75" id="Allocation" value="<%=rs.getString("DBID")%>" readonly="readonly">  

Then you need to include this string variable as a "query-string" when you are calling next JSP from current JSP.

I did not find the code where you are calling the next-JSP from the first-JSP.
Please show me how you are calling the next jsp from the FIRST-JSP .
Then I will show you how to append value "all_DBIDs" as a query string to next JSP.

Edited by subramanya.vl

0

In short
If the usl for next jsp is like "next_page.jsp"
then you can append the querystring linke this
next_page.jsp?dbids=<%=all_DBIDs%>

Now you can get the complete "all_DBIDs" on next page by using the code like this

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.