日期:2014-05-17  浏览次数:20745 次

如何在html中用jave读取session
本帖最后由 u013786943 于 2014-04-13 18:11:08 编辑
session中有一个变量 exampleid。

能否在html中用java读取exampleid的指。如果exampleid的值为99999999,然后跳向一个指定页面,比如www.example.com/example/login.php;如果不是99999999,则将值传给后续php程序。

能否实现?如何实现?
------解决方案--------------------
试试这样,
<%
String strExampleid = request.getParameter("exampleid");
int exampleid = Integer.parseInt(strExampleid);
if(99999999 == exampleid)
response.sendRedirect("http://www.example.com/example/login.php");
else
response.sendRedirect("http://www.example.com/example/login.php");

%>

不过获取数值时候最好用try catch 不然当传的是字符串时会出错。
------解决方案--------------------
引用:
Quote: 引用:

试试这样,
<%
String strExampleid = request.getParameter("exampleid");
int exampleid = Integer.parseInt(strExampleid);
if(99999999 == exampleid)
response.sendRedirect("http://www.example.com/example/login.php");
else
response.sendRedirect("http://www.example.com/example/login.php");

%>

不过获取数值时候最好用try catch 不然当传的是字符串时会出错。



这个用放在html页面的。直接放进去,就可以吗?

这是用在jsp的,<% %>这东西html不认识,所以你放进去页面会把你放的源码显示出来
------解决方案--------------------
文件名是index.jsp , 不是index.html

<%
这里是 java 的代码 。
 %>