类型转换(急)!!!!!!!!!!!!!!

chengjunlin55555 2004-10-27 11:54:14
2 个页面间传值老出错,请帮忙!
1。地一个页面的代码:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<title>无标题文档</title>
</head>

<body>
<%
request.setAttribute("Name",12);
request.setAttribute("Password",45);
%>

<jsp:forward page="page2.jsp"/>
</body>
</html>
2。第 个页面的代码:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.lang.Object" errorPage="" %>
<html>
<head>
<title>无标题文档</title>
</head>

<body>
<%
//Object sname = new String("");
//sname = request.getAttribute("Name");String snames = new String(sname);
//String spsd = request.getAttribute("Password");
//int Name=Integer.parseInt(snames);
//int Password=Integer.parseInt(spsd);
//out.println(sname+".......=Name");
//out.println(Name+".......=Name");
// out.println(Password+"......=Password");
String Name=(String)request.getAttribute("Name");
String pasw=(String)request.getAttribute("Password");
out.println("Name");
out.println("pasw");
%>
</body>
</html>
跪求了!!!
...全文
87 点赞 收藏 6
写回复
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
tom2005 2004-10-27
你可以传字符串
request.setAttribute("Name","12");

out.println(Name);
回复
chengjunlin55555 2004-10-27
楼上的不行呀?
回复
yizdream 2004-10-27
request.setAttribute("Name",new Integer(12));

看看行不行啊。。。。
回复
chengjunlin55555 2004-10-27
自己顶
回复
chengjunlin55555 2004-10-27
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: 7 in the jsp file: /page1.jsp

Generated servlet error:
[javac] Compiling 1 source file

E:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\test\page1_jsp.java:50: setAttribute(java.lang.String,java.lang.Object) in javax.servlet.ServletRequest cannot be applied to (java.lang.String,int)
request.setAttribute("Name",12);
^



An error occurred at line: 7 in the jsp file: /page1.jsp

Generated servlet error:
E:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\test\page1_jsp.java:51: setAttribute(java.lang.String,java.lang.Object) in javax.servlet.ServletRequest cannot be applied to (java.lang.String,int)
request.setAttribute("Password",45);
^
2 errors


at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:130)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293)
at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:353)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:370)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:473)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:190)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)



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

Apache Tomcat/4.1.30
回复
Aa7643 2004-10-27
request.setAttribute("Name","12");
request.setAttribute("Password","45");
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告