• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

The method setAttribute(String, Object) in the type HttpSession is not applicable for

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Sir,

While i am doing this project before inserting this sessionAttribute my programme was worked fine with JDK 1.5.1 but after this following error had been occuring after uninstalling my JDK 1.5.1 and installed my new JDK 1.6.1

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

An error occurred at line: 13 in the jsp file: /forward.jsp
Generated servlet error:

The method setAttribute(String, Object) in the type HttpSession is not applicable for the arguments (String, int)

SOURCE CODE :
<%@ page import="java.sql.*, java.io.*, java.util.*" %>
<% Class.forName("com.mysql.jdbc.Driver");%>

<%
Connection connection = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/tpl", "root", "root");
Statement statement = connection.createStatement() ;
session.removeAttribute("eno");
ResultSet resultset = statement.executeQuery("select * from emast where eno="+ request.getParameter("eno")+" AND pwd='" +request.getParameter("pwd")+"'");

%>

<% if (resultset.next()) {
session.setAttribute("eno", resultset.getInt(1));
%>

<jsp:forward page="index.jsp">
<jsp:param name="eno" value="<%= resultset.getInt(1)%>"/>
<jsp:param name="fname" value="<%= resultset.getString(3)%>"/>
<jsp:param name="desig" value="<%= resultset.getString(4)%>"/>
<jsp:param name="dept" value="<%= resultset.getString(5)%>"/>
</jsp:forward>
<%
}
else
{
%>
<%@ include file="login.jsp"%>
<center><b><%="Sorry! Enter the Correct Password"%></b></center>
<%
}
%>

PLEASE HELP IN THIS REGARD
WAITING FOR YOUR REPLY
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Suryanarayanan Jayaraman:

An error occurred at line: 13 in the jsp file: /forward.jsp
Generated servlet error:

The method setAttribute(String, Object) in the type HttpSession is not applicable for the arguments (String, int)



Hi,

it shows your jdk is not support boxing and unboxing.This type of error will come in jdk1.4(before release of jdk1.5)

i guess you are using IDE . just confirm your source is pointing to the jdk 1.6 only ..

example, if you use netbeans, by default it points jdk1.4

Hope This Helps
[ November 02, 2008: Message edited by: seetharaman venkatasamy ]
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Javaranch Suryanarayanan Jayaraman

As said above the problem is with the boxing of the int, a better approach would be using the wrapper class or a String type.
And its not a really good practice to have all that connection code in the JSP.
[ November 02, 2008: Message edited by: Amit Ghorpade ]
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its not good practise to write the code as session.setAttribute("eno", resultset.getInt(1));
Please always avoid this things and use session.setAttribute("eno", new Integer(resultset.getInt(1)));
 
Suryanarayanan Jayaraman
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Find the prompt reply, in future course of time i may not make this mistake again as suggested by you. I had changed my programed as you
mentioned by you like this : session.setAttribute("eno", new Integer(resultset.getInt(1)));
but now the error is like this:
HTTP Status 500 -

type Exception report

message

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

exception

javax.servlet.ServletException: com.mysql.jdbc.Driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageExceptionkindly me give me out your valuable suggestion to solve this problem premenately
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic