0

Hi I am very new to jsp but I just wondering that how do we get value from jsp page and pass value on to ios device example this is part of jsp page after login

   <%
// ---------------------------------------- Get Parameter username, password >>
String sessUser =  (String)session.getValue("sessUser");
String sessCustomer =  (String)session.getValue("sessCustomer");
String str_Name= "";
String str_SurName= "";
String userid= sessUser;
USERS.connectDB(JDBC_DRIVER,DATABASE_URL,DbUser,DbPwd);
ResultSet rs=null;
rs =  USERS.QueryByUserId(sessCustomer,userid,"","");
// --------------------------------------- Query solution department of login user >>
if (rs.next()) {
    str_Name = rs.getString("nme");
    str_SurName = rs.getString("surnme");
}rs.close();
%>
<body topmargin="0" leftmargin="0" bottommargine="0" bgcolor="black">
<table width="100%" cellPadding="0" cellSpacing="0" border="0" bgcolor="#494949">
    <tr valign="top">

if I want to get value of str_name and display on iOS device .. what method can I use

Thank you

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Pakaphol Buathon
  • 188
  • 3
  • 18

1 Answers1

0

I recommend reading this thread regarding scriptlets in jsp pages:

How to avoid Java code in JSP files?

and for a basic tutorial:

http://www.tutorialspoint.com/jsp/jsp_java_beans.htm

To answer your question: I think this should work:

<td>Name</td><td><%= str_name %></td>

But I would prefer putting the code into a backend bean and access the data the following way:

UserBean.java (a session bean):

...

public void getUserName(){
  String sessUser =  (String) request.getSession().getAttribute("sessUser");
  String sessCustomer =  (String) request.getSession().getAttribute("sessCustomer");
  String str_Name= "";
  String str_SurName= "";
  String userid= sessUser;

  USERS.connectDB(JDBC_DRIVER,DATABASE_URL,DbUser,DbPwd);
  ResultSet rs=null;
  rs =  USERS.QueryByUserId(sessCustomer,userid,"","");
  if (rs.next()) {
    str_Name = rs.getString("nme");
    str_SurName = rs.getString("surnme");
  }
  rs.close();

  return str_Name;
}

...

JSP Page:

<jsp:useBean id="userBean" class="test.here.UserBean"/>

...

<table width="100%" cellPadding="0" cellSpacing="0" border="0" bgcolor="#494949">
  <tr valign="top">
    <td>Name</td>
    <td><jsp:getProperty name="userBean" property="userName"/></td>
  </tr>

...
Community
  • 1
  • 1
Chris K.
  • 46
  • 5