您好我对jsp很新,但我只是想知道我们如何从jsp页面获取值并将值传递给ios设备示例这是登录后jsp页面的一部分
<%
// ---------------------------------------- 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">
如果我想获得str_name的值并在iOS设备上显示..我可以使用什么方法
谢谢
答案 0 :(得分:0)
我建议在jsp页面中阅读关于scriptlet的这个帖子:
How to avoid Java code in JSP files?
以及基础教程:
http://www.tutorialspoint.com/jsp/jsp_java_beans.htm
回答你的问题:我认为这应该有效:
<td>Name</td><td><%= str_name %></td>
但我更愿意将代码放入后端bean并按以下方式访问数据:
UserBean.java(会话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页面:
<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>
...