Having trouble getting my AttachmentServlet.java and FilterServelt.java to compile

the following is the code (for which the error applies) then the error for each.

AttachmentServlet.java

HttpSession session = request.getSession();
ServletOutputStream out = response.getOutputStream();
int msgNum = Integer.parseInt(request.getParameter("message"));
int partNum = Integer.parseInt(request.getParameter("part"));
MailUserBean mailuser = (MailUserBean)session.getAttribute("mailuser");

cannot find symbol
symbol : method getAttribute(java.lang.String)
location: interface javax.servlet.http.HttpSession

inconvertible types
found : javax.servlet.http.HttpSession.getAttribute
required: demo.MailUserBean


FilterServlet.java

HttpSession session = request.getSession();
MailUserBean mailuser = (MailUserBean)session.getAttribute("mailuser");
String servletPath = request.getServletPath();
servletPath = servletPath.concat(".jsp");

cannot find symbol
symbol : method getAttribute(java.lang.String)
location: interface javax.servlet.http.HttpSession

inconvertible types
found : javax.servlet.http.HttpSession.getAttribute
required: demo.MailUserBean

Dani AI

Generated

Short diagnosis and a practical checklist.

Contrary to , javax.servlet.http.HttpSession does provide attribute accessors — the compiler error here means the project is compiling against a different/corrupt HttpSession type (or another servlet JAR) so the call your code expects does not exist at compile time. That also explains the odd "inconvertible types" symptom: the compiler has resolved the wrong type, not your bean. and were on the right track with version/class issues and null-checking the session bean; the missing piece is fixing the compile-time classpath.

What to check (in order)

  • Verify which HttpSession is on the compile classpath. In your IDE use “Open Type” on javax.servlet.http.HttpSession or inspect the servlet jar with these commands:
    
    # Unix-like
    jar tf /path/to/servlet-api.jar | grep HttpSession
    javap -classpath /path/to/servlet-api.jar javax.servlet.http.HttpSession

Windows

jar tf C:\path\to\servlet-api.jar | findstr HttpSession

- Remove duplicate servlet jars from the webapp. Do not put servlet-api/servlet.jar in WEB-INF/lib; the container supplies it. For Maven projects use provided scope:

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>

- Ensure there are no other classes named HttpSession in your packages and that your source imports javax.servlet.http.HttpSession (or temporarily use the fully qualified type to confirm).
- Clean/rebuild after fixing libraries. Also verify there are no earlier syntax errors that make the compiler mis-parse the cast expression.

About the WSDL/SOAP warning
That warning comes from the WSDL codegen (it’s telling you it ignored a SOAP 1.2 port unless extensions are allowed). Two practical options: run the generator with the extension flag (for JAX-WS/tools use the tool’s -extension switch) or update your IDE/tooling (as noted in this thread, an IDE upgrade resolved it). Example:

wsimport -extension -keep -p com.example.client



After the classpath is fixed the session-bean pattern suggested by @deepalihanand (retrieve, null-check, create and set if absent) will compile and behave correctly.

Recommended Answers

All 6 Replies

there is no such thing as javax.servlet.http.HttpSession.getAttribute()

I think that you are using different version of MailUserBean.

According to me - try this :

HttpSession session = request.getSession();

MailUserBean nameBean =
      (MailUserBean)session.getAttribute("nameBean");

    if (nameBean == null) {
      ...Your steps //String firstName = request.getParameter("firstName");
      //String lastName = request.getParameter("lastName");
      //nameBean = new MailUserBean(firstName, lastName);
      session.setAttribute("nameBean", nameBean);
    }

Do let me know, if it works. If it does not do send the complete code.

Thanks

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

Okay got past the last problem, but now it is showing the following error, but I'm not sure where exactly it wants me to add the -extension

[WARNING] Ignoring SOAP port "LicenseServiceSoap12": it uses non-standard SOAP 1.2 binding.
You must specify the "-extension" option to use this binding.
line 248 of file:/C:/softwaresource/unchanged/GTDev/GlobalTraderUtils/xml-resources/web-service-references/LicenseService.asmx/wsdl/software.globaltradertech.com/LicenseService.asmx.wsdl

Any ideas.

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

Okay got past the last problem, but now it is showing the following error, but I'm not sure where exactly it wants me to add the -extension

[WARNING] Ignoring SOAP port "LicenseServiceSoap12": it uses non-standard SOAP 1.2 binding.
You must specify the "-extension" option to use this binding.
line 248 of file:/C:/softwaresource/unchanged/GTDev/GlobalTraderUtils/xml-resources/web-service-references/LicenseService.asmx/wsdl/software.globaltradertech.com/LicenseService.asmx.wsdl

Any ideas.

Hi,
the missing -extension switch in J2SE project is a known bug in NB5.5.1 which will be fixed soon in a hotfix update.

Yes, good call, 5.5 compiled it fine.

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.