#java servlets issues
107 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @last plank! Please use
/closeor theClose Postbutton 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.
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
i worked throuygh it and managed to fix it but i have a new error now
so the first part of it works
but now it seems to have a issue with the second half
when i hit calculate
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
which part of it?
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
Yeah, for what you're showing that's very much not normal that it intervenes
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.
//
// 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.
not sure why some of it didnt format but thats my calculationsservlet.class
Could you try maybe a .java instead?
Also I'd be wary about all the compilation errors
the file i sent is from the build folder
but the .java version is under the src
should i send that instead?
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
doesnt it technically compile but stop working halfway through at the specific point?
or am i looking at things wrong
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
ah alright
im thinking its the .class file because it says this in the error after clicking the button
This is a runtime thing. Forget about running stuff, your project doesn't compile. It can't run
First seeing the compile errors would help
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)
this is the console when running
this is the localhost log from tomcat
That's not a compiling command. Also you have an IDE. Look at the errors in the IDE
Leave tomcat alone and compile first
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
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
Admittedly that's weird, but I don't see you opening any files regardless
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
Then just mvn clean for now
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.
oh yeah it did remove the class files
And the build directory?
And when you run mvn install they come back?
it didnt remove from build directory
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
Mmmh. But you weren't trying to modify it. I guess close the IDE, delete them, and reopen the IDE
I'm surprised mvn clean left both, but fine
errors seem to look the same
Errors after you do what? Last time I checked, we had deleted all .class files
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.
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
Any .class file somewhere?
What does it look like opening them?
That's more like it.
Not far from them, under target, you should find a .war file. Try and run that in tomcat
Not a problem. It's just what you're supposed to give tomcat to run
How do I make tomcat run it?