`

关于Request中setAttribute(String name,Object obj)的参数问

阅读更多
在平时的开发中,您可能会碰到如下的错误提示:
The method setAttribute(String, Object) in the type ServletRequest is not
applicable for the arguments (String, int)

从错误提示,可以看出问题主要在于类型匹配错误,需要进行转型。下面讲下个人的解决方案
(1)转型当然是可以解决的;
(2)因为转型有时转来转去麻烦,如果不想转的话,可以试试更换JDK版本。我在Myeclipse(版本6.5)下做过测试,在创建工程的时候选择J2EE1.4会报以上错误,如果选择J2EE5.0则不会报错。
分享到:
评论
2 楼 wikimo 2009-09-09  
@ wanglingzhong
这个我到没有深入去研究过,估计得查看下源码是如何实现的。。。
1 楼 wanglingzhong 2009-09-09  
我也遇到了这个问题,为什么string类型可以接受,却不能数字类型?向上转型应该是自动的吧!

相关推荐

    Java+javabean

    The method setAttribute String Object in the type ServletRequest is not applicable for the arguments String int

    request.setAttribute 语句前总显示红色感叹号解决办法 HTTP Status 500 -

    The method setAttribute(String, Object) in the type ServletRequest is not applicable for the arguments (String, double) y2ssh.sg.chp1.action.AddAction.execute(AddAction.java:18) y2ssh.sg.chp1....

    JSP request.setAttribute()详解及实例

    javascript request.setAttribute()详解 request.setAttribute()怎么用的? JSP1代码 String [] test=new String[2]; test[0]=1; test[1]=2; request.setAttribute(test,test) ; response.sendRedirect(jsp2.jsp); ...

    jsp内置对象的用法

    10 void setAttribute(String name,Object obj,int scope) 在指定范围内设置属性及属性值 11 public Object getAttribute(String name) 取属性的值 12 Object getAttribute(String name,int scope) 在指定范围...

    hibernate sprint 封装应用

    String xm = request.getParameter("xm"); String rxsj = request.getParameter("rxsj"); String yx = request.getParameter("yx"); String zy = request.getParameter("zy"); String sf = request.getParameter("sf...

    JavaScript中setAttribute用法介绍

    我们经常需要在JavaScript中给Element动态添加各种属性,这可以通过使用setAttribute()来实现,这就涉及到了浏览器的兼容性问题

    ognl源码包值得用一用

    request.setAttribute(name, value); } else { // 文件名的处理 String name = item.getFieldName(); String value = item.getString("GBK"); int start = value.lastIndexOf("\\");...

    java中管理员板块

    String name=request.getParameter("name"); String sortNo=request.getParameter("sortNo"); if(name==null||name.equals("")){ request.setAttribute("msg", "请输入分区名称"); request....

    JAVA程序员面试题

    setAttribute(String name,Object):设置名字为name的request的参数值 getAttribute(String name):返回由name指定的属性值 getAttributeNames():返回request对象所有属性的名字集合,结果是一个枚举的实例 get...

    jsp九大内置对象

     ● public void setAttribute(String key,Object obj):将参数Object指定的对象obj添加到Session对象中,并为添加的对象指定一个索引关键字。  ● public Object getAttribute(String key):获取Session对象中...

    weChatpay完整版java

    String requestUrl = Constants.GET_OPENID_ACCESSTOKEN_URL.replace("APPID" , appid).replace("APPSECRET" , appsecret).replace("CODE" , code); String json = httpRequest(requestUrl , "GET" , null); ...

    JSP应用基础.ppt

    setAttribute(String name,Object):设置名字为name的request的参数值; getAttribute(String name):返回由name指定的属性值; getAttributeNames():返回request对象所有属性的名字集合,结果是一个枚举的实例;

    getAttribute和getParameter区别.

    1.getAttribute是取得jsp中 用setAttribute設定的attribute 2.parameter得到的是string;attribute得到的是object 3.request.getParameter()方法传递的数据,会从Web客户端传到Web服务器端,代表HTTP请求数据;...

    学生信息管理系统

    String action request getParameter "action" ; Teacher t new Teacher ; t setUsername request getParameter "username" ; if "register" equals action { t set...

    javascript中setAttribute兼容性用法分析

    本文实例分析了javascript中setAttribute兼容性用法。...setAttribute(string name, string value):增加一个指定名称和值的新属性,或者把一个现有的属性设定为指定的值。 1、样式问题 setAttribu

    数据库测试test.sql

    // String methodName = request.getParameter("method"); // // //根据method属性的值调用相应的方法 // if("login".equals(methodName)){ // this.login(request,response); // }else if("register".equals(method...

    javaEE j2ee 大学考试题库,j2ee开发面试题库-1

    request.setAttribute("name","zhang"); response.sendRedirect("http://localhost:8080/MVC/MyServlt"); 那么在 MyServlet 中可以使用( )方法把属性 name 的值取出来。 A. String str=request.getAttribute("name...

    jsp基础精华详解

    String name = request.getParameter("username"); String pwd =request.getPareameter("pwd"); 内部跳转: LoginServlet request.getRequestDispatcher("index.jsp").forward(request, resposne); 外部跳转: ...

Global site tag (gtag.js) - Google Analytics