#java servlets issues

107 messages · Page 1 of 1 (latest)

last plank
#

I've been trying to run this local host for a simple website calculator but i get this output:

amber violetBOT
#

This post has been reserved for your question.

Hey @last plank! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

last plank
#

and here is the result when i try to run with site:run

sharp hound
#

That's not what deploy and site mean in Maven linguo. Those are goals that work also for library projects. Obviously you're not going to have a library "run" nor "be a website"

#

I'm not sure how do you make a servlet run with Maven, it's been a while. Maybe you just need to have it packaged, then you need to copy the package to your tomcat directory and run tomcat as usual. IntelliJ might help with these

last plank
#

so the first part of it works

#

but now it seems to have a issue with the second half

#

when i hit calculate

sharp hound
#

It seems to be complaining that you designated something for a role for which it has to be a servlet, but it's not a servlet

#

We'd be needing the code here

last plank
sharp hound
#

I'd have guessed everything that has a chance to designate a class that may need to be a servlet, as well as the class itself who'd need to be a servlet and is seen as not one. But I'm not very clear about the need to restrict what you're going to show

last plank
#

just the limitation with discord on file size

#

but let me see

sharp hound
#

Yeah, for what you're showing that's very much not normal that it intervenes

amber violetBOT
#

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

desert forumBOT
#

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package controller;

import java.io.IOException;

public class CalculationsServlet {
   private static final long serialVersionUID = 1L;

   public CalculationsServlet() {
       throw new Error("Unresolved compilation problems: \n\tThe import javax.servlet cannot be resolved\n\tThe import javax.servlet cannot be resolved\n\tThe import javax.servlet cannot be resolved\n\tThe import javax.servlet cannot be resolved\n\tThe import javax.servlet cannot be resolved\n\tWebServlet cannot be resolved to a type\n\tHttpServlet cannot be resolved to a type\n\tHttpServletRequest cannot be resolved to a type\n\tHttpServletResponse cannot be resolved to a type\n\tServletException cannot be resolved to a type\n\tHttpServletRequest cannot be resolved to a type\n\tHttpServletResponse cannot be resolved to a type\n\tServletException cannot be resolved to a type\n");
   }

   protected void doGet(HttpServletRequest var1, HttpServletResponse var2) throws ServletException, IOException {
       throw new Error("Unresolved compilation problems: \n\tHttpServletRequest cannot be resolved to a type\n\tHttpServletResponse cannot be resolved to a type\n\tServletException cannot be resolved to a type\n");
   }

   protected void doPost(HttpServletRequest var1, HttpServletResponse var2) throws ServletException, IOException {
       throw new Error("Unresolved compilation problems: \n\tHttpServletRequest cannot be resolved to a type\n\tHttpServletResponse cannot be resolved to a type\n\tServletException cannot be resolved to a type\n");
   }
} ```

This message has been formatted automatically. You can disable this using /preferences.

last plank
#

not sure why some of it didnt format but thats my calculationsservlet.class

sharp hound
#

Could you try maybe a .java instead?

#

Also I'd be wary about all the compilation errors

last plank
#

the file i sent is from the build folder

#

but the .java version is under the src

#

should i send that instead?

sharp hound
#

I mean, technically we've established that your project doesn't compile. So we'd need to switch the goal to finding the compilation errors

#

They would normally be everywhere

last plank
#

doesnt it technically compile but stop working halfway through at the specific point?

#

or am i looking at things wrong

sharp hound
#

Usually, "it compiles" is a yes/no question. Either everything compiles, or it doesn't compile. It's not like it's difficult to have a project without any compilation error

last plank
#

ah alright

#

im thinking its the .class file because it says this in the error after clicking the button

sharp hound
#

This is a runtime thing. Forget about running stuff, your project doesn't compile. It can't run

last plank
#

alright

#

how do i go about fixing it?

sharp hound
#

First seeing the compile errors would help

last plank
#

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:673)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:391)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:896)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1736)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
at java.base/java.lang.Thread.run(Thread.java:1570)

last plank
last plank
sharp hound
#

That's not a compiling command. Also you have an IDE. Look at the errors in the IDE

#

Leave tomcat alone and compile first

last plank
#

alright

#

wait im a bit confused now how should i compile it

#

sorry im a bit new to this so i might have some stupid questions

sharp hound
#

You shouldn't. You want to see the errors. For that you open your files. Your IDE will show the error obtained in attempts to compile the files

last plank
#

the ide itself doesnt seem to show any issues

sharp hound
#

Admittedly that's weird, but I don't see you opening any files regardless

last plank
#

do you mean opening files like this?

sharp hound
#

Yes. But that looks fine. No idea how did you obtain that .class file

#

I guess run mvn clean install and let's see if something changes

last plank
#

alright done

#

still is the same

sharp hound
#

Then just mvn clean for now

last plank
#

should i run after mvn clean?

#

but seems to be the same

sharp hound
#

mvn clean is supposed to clean .class files, they're supposed to not exist anymore afterwards

#

Though I'm not entirely sure where does maven keep the class files.

last plank
#

oh yeah it did remove the class files

sharp hound
#

And the build directory?

last plank
#

yes

#

wait no

sharp hound
#

And when you run mvn install they come back?

last plank
#

it didnt remove from build directory

sharp hound
#

Look, remove everything that is a .class or called build or target. If mvn clean doesn't remove it then delete it yourself

#

Then we try again

last plank
#

alright

#

says this when i try to delete it

sharp hound
#

Mmmh. But you weren't trying to modify it. I guess close the IDE, delete them, and reopen the IDE

last plank
#

alright

#

removed the .class files

#

there was one under target as well

sharp hound
#

I'm surprised mvn clean left both, but fine

last plank
#

errors seem to look the same

sharp hound
#

Errors after you do what? Last time I checked, we had deleted all .class files

last plank
#

i tried running it

#

am i not supposed to?

sharp hound
#

Well, usually one would only run something that exists. Not something that was deleted. But eh, creativity

#

Anyway, let's mvn install and see whether there are .class files somewhere.

last plank
#

im just getting a bit carried away with checking for changes

#

[INFO] --- war:3.4.0:war (default-war) @ slab-calculations ---
[INFO] Packaging webapp
[INFO] Assembling webapp [slab-calculations] in [/Users/sushantpotu/Downloads/trial/target/slab-calculations]
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/sushantpotu/Downloads/trial/src/main/webapp]
[INFO] Building war: /Users/sushantpotu/Downloads/trial/target/slab-calculations.war
[INFO]
[INFO] --- install:3.1.1:install (default-install) @ slab-calculations ---
[INFO] Installing /Users/sushantpotu/Downloads/trial/pom.xml to /Users/sushantpotu/.m2/repository/org/example/slab-calculations/1.0-SNAPSHOT/slab-calculations-1.0-SNAPSHOT.pom
[INFO] Installing /Users/sushantpotu/Downloads/trial/target/slab-calculations.war to /Users/sushantpotu/.m2/repository/org/example/slab-calculations/1.0-SNAPSHOT/slab-calculations-1.0-SNAPSHOT.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.846 s
[INFO] Finished at: 2024-03-28T14:13:46-04:00
[INFO] --------------------------------------------------

#

this is what it says

sharp hound
#

Any .class file somewhere?

last plank
#

two under target

#

the goldish colored part

sharp hound
#

What does it look like opening them?

last plank
sharp hound
#

That's more like it.

#

Not far from them, under target, you should find a .war file. Try and run that in tomcat

last plank
#

is it this one?

#

it doesnt let me open it or anything

sharp hound
#

Not a problem. It's just what you're supposed to give tomcat to run

last plank
#

How do I make tomcat run it?

last plank
#

tried putting the war file in the webapps folder but didnt work, logs folder was empty

#

not sure what to do now