首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

哪位高手能给小弟我指点一下session对象的setAttribute()和getAttribute()方法如何使用啊

2013-09-11 
谁能给我指点一下session对象的setAttribute()和getAttribute()方法怎么使用啊?这是我写的一个程序,过程是

谁能给我指点一下session对象的setAttribute()和getAttribute()方法怎么使用啊?
这是我写的一个程序,过程是在choice.jsp文件中选择要买的物品,提交以后在session.jsp文件中将要买的物品显示出来。

choice.jsp文件如下:
<html>
<head>
<title>
Doing   Some   Shoppings
</title>
</head>
<body>
<form   action= "show.jsp "   method= "post ">
    What   do   you   want   to   buy: <input   type= "radio "   name= "choice "   value= "basketball "   checked> basketball
                                                <input   type= "radio "   name= "choice "   value= "football "> football
                                                <input   type= "radio "   name= "choice "   value= "baseball "> baseball
                                                <br> <br>
                                                <input   type= "submit "   name= "go ">
                                                <input   type= "reset "   name= "reset ">
                                               
</form>
  <%  
  session.setArribute( "choice ",value)
    %>
</body>
</html>
报错如下:
type   Exception   report

message  

description   The   server   encountered   an   internal   error   ()   that   prevented   it   from   fulfilling   this   request.

exception  

org.apache.jasper.JasperException:   Unable   to   compile   class   for   JSP

An   error   occurred   at   line:   17   in   the   jsp   file:   /111/choice1.jsp
Generated   servlet   error:
C:\Program   Files\Apache   Software   Foundation\Tomcat   5.0\work\Catalina\localhost\web\org\apache\jsp\_111\choice1_jsp.java:61:   '; '   expected
   
^
1   error


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)


org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note   The   full   stack   trace   of   the   root   cause   is   available   in   the   Apache   Tomcat/5.0.28   logs.


show.jsp文件如下:
<%@   page   contentType= "text/html;charset=GB2312 "   %>
<HTML>

<BODY>
  the   things   you   bought   are: <%session.getAttribrute( "choice ");   %>

</BODY>
</HTML>

[解决办法]
value 是radio属性

但是你不能直接再java代码里面用

你要在show.jsp里面 按下面的得到这个选中的值


String value= request.getParameter( "choice ");

然后out.println(value);
[解决办法]
session.setArribute( "choice ",value);中的value没有定义,一般session不这么用,session是用来保存客户提交的信息的,通常一个页面用来给客户提交信息,也就你写的choise.jsp;客户再把信息提交给session页面,我们记为session.jsp;这个页面中就要用到session.setArribute( "choice ",value);问题来了,其中的value是一个变量,是一个java变量,它的值是怎么获得的呢?这就要通过你在choise里面定义的表单form来获得了,用request对象获得赋值给value,然后在通过session.setArribute( "choice ",value);最后就是你的show.jsp页面了这个时候用session.getAttribrute( "choice "); 就可以获得刚刚set的值。
说的不好,见谅~~~
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html

热点排行