Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!

Lakshi Meghoo

Greenhorn
+ Follow
since Feb 03, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Lakshi Meghoo

Hi All,
Can anyone tell me how to make a two way communication between a client and a server MIDlet applications. I want to send several messages between two devices. I modified a hello world application, but I can either read or write on the communication stream. Can anyone tell me how to do both read and write in using RFCOMM in one communication stream?

9 years ago
I tried my code in jsp and html format. It works well. I think the problem is about the wap pages. Perhaps some header tags are missing.
9 years ago
JSP
Thanks for your willingness to help.
I understand my application is not the simple html and jsp. Does anyone familiar with WAP can help me to sort this problem?
9 years ago
JSP
Hi,

Balagopal

I tried the codes you gave me but still the session returns null.

Do you have other suggestions?

I really need to solve this problem.

9 years ago
JSP
Hi all,

I am developing a WAP application using jsp. I'm saving a variable in session in 1 page and retrieving the value in another page.


My codes are as follows:

chooseques.jsp

<%@ page contentType="text/vnd.wap.wml" %>

<%@page language="java" import="java.sql.*" %>


<%

Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "asssys";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "";
Statement st;
String mod1 = request.getParameter("mod");
int i=1;
int j=0;

session.setAttribute( "module1", mod1 );

System.out.println("module1="+session.getAttribute("module1"));



try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();

con = DriverManager.getConnection(url+dbName,userName,password);
}
catch(Exception e){
System.out.println(e.getMessage());
}


String s="select * from questions where questions.mid="+mod1;

System.out.println(mod1);

%>

<card id="card2" title="Choose questions">
<form method="POST" action="choosestud.jsp">

<%
try{
st = con.createStatement();
ResultSet rs=st.executeQuery(s);


while (rs.next()){%>

<p align="left">

<b><%=i%>. <%=rs.getString(3)%></b><br/>
<b>A.</b> <%=rs.getString(4)%><br/>
<b>B.</b> <%=rs.getString(5)%><br/>
<b>C.</b> <%=rs.getString(6)%><br/>
<b>D.</b> <%=rs.getString(7)%><br/>
<input type="checkbox" name="chk<%=+i%>" checked="checked" value="<%=rs.getString(1)%>" />
<br/>
<br/>
<hr/><hr/><br/>

<% i++; j++;
}//while
%>

//I want to save an integer value in session. I'm casting it to string first.
<% String count = Integer.toString(j);



session.setAttribute( "sess_count", count );


System.out.println("sess_count="+session.getAttribute("sess_count"));// This displays the sess_count correctly




%>

<p><input type="submit" value="Submit" ></p>
</form>
</card>

<%


rs.close();
con.close();

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


%>




displayques.jsp


<%@ page contentType="text/vnd.wap.wml" %>

<%@page language="java" import="java.sql.*" %>
<%


String count =(String)session.getAttribute("sess_count");//I'm retriving the session variable but it returns null!!


int counter = Integer.parseInt(count1);

System.out.println("count ="+count);



Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "asssys";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "";
Statement st;

try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();

con = DriverManager.getConnection(url+dbName,userName,password);
}
catch(Exception e){
System.out.println(e.getMessage());
}


int i=0;
int j=1;
String[] arr = new String[counter];
%>

<card id="card3" title="Display selected questions">

<%

while (i<counter){
arr[i] = request.getParameter("chk"+j);

String s="select * from questions where questions.qid="+request.getParameter("chk"+j);



try{
st = con.createStatement();
ResultSet rs=st.executeQuery(s);
rs.next();

%>

<p align="left">

<b><%=j%>. <%=rs.getString(3)%></b><br/>
<b>A.</b> <%=rs.getString(4)%><br/>
<b>B.</b> <%=rs.getString(5)%><br/>
<b>C.</b> <%=rs.getString(6)%><br/>
<b>D.</b> <%=rs.getString(7)%><br/>
<input type="hidden" name="chk<%=rs.getString(1)%>" value="<%=rs.getString(1)%>" />
<br/>
Display qid: <%=rs.getString(1)%>
<hr/><hr/><br/></p>


<%

rs.close();

}//try

catch(Exception e){
System.out.println(e.getMessage());
}//catch

i++; j++;

}// while


con.close();
%>

------------------------------------------------------------------------------

Can anyone tell me why the session variable is returning null value? What is the problem with the code?
Your reply will be of great help.


9 years ago
JSP