How to run Servlet?

已回答

Hello, I just switched from Eclipse, and here everything is so different...I have a problem with a VERY simple issue. I just want to see my Servlet in browser. With jsp there is no problem, but when I click "run" when my Servlet windos is opened - all that is running is Tomcat itself. It's does't go to my default browser, so I can't see anything.  

评论操作 固定链接

I checked it. If doesn't unswer my question at my current level. I just want one I thought simple thing in Eclipse. To run servlet on Tomcat. To see for example the output of PrintWriter....Enything. It should be simple. In Eclipse it was avalible without any configuration. 

0
评论操作 固定链接

This tutorial above is focued on Comunity version of InteliiJ. I've got Utimate verion. But thanks anyway, I'll try that. Does anyone have more suggestions regarding my issue?

0
评论操作 固定链接

A bit of it - adding mapping to xml - solved case! Thank You Petr Rastegaev!:)

0
评论操作 固定链接

Hello there, I've the same issue.

In eclipse, I create a dynamic web project. I create a servlet and when I run it, it works.

But in intellij, I can only create a web app, no a dynamic web project. So when I start the app, I obtain the index.jsp and not the wanted servlet.... The tutorials don't solve my problems. Thanks

0
评论操作 固定链接

Just change the URL you open to the servlet mapped URL, if the issue persists please share your project: https://uploads.services.jetbrains.com/.

0
评论操作 固定链接

It works. I finally understand 5he difference. In intellij you have to modify the URL. You can't do the right click "run as" of eclipse Ide. Thanks

0
评论操作 固定链接

Hi Krysnn,

 

And how do you do that exactly, as I have the same problem.

0
评论操作 固定链接

I'm having this same issue. I can produce a successful servlet from a Java Enterprise project. When I create a Gradle project and add additional web framework, the servlet I create is not found. I suspect this is an artifact issue, but I can't resolve it. I'm using the <project-name>:war exploded artifact. There are two additional Gradle war files but they do not work.

   
0
评论操作 固定链接

Please upload a sample project that doesn't work at https://uploads.services.jetbrains.com/ .

0
评论操作 固定链接

I uploaded a file named web-customer-tracker.zip. The index page will display when I run the tomcat 9.0.35 server but the servlet I created is not found. For the server configuration, I'm using the web-customer-tracker:war exploded artifact. If I use the Gradle : com.tracker.customer : web-customer-tracker-1.0.0-SNAPSHOT.war (exploded) artifact, it results in a failure during artifact deployment.

 

0
评论操作 固定链接

There are multiple issues with the project configuration and one known issue with IntelliJ IDEA that is causing the exploded artifact to not build: https://youtrack.jetbrains.com/issue/IDEA-176700 .

A workaround is to build and run using IDE by changing this setting: https://i.imgur.com/HpeUaUE.png .

As for the project configuration, web app directory must be src/main/webapp and not web for Gradle projects.

After fixing all the above, the project builds, deploys and runs as expected:

https://i.imgur.com/lijGGc6.png
https://i.imgur.com/lU6Z0zL.png
https://i.imgur.com/bo4CaNx.png .

Fixed project: https://www.dropbox.com/t/aKPwIcGmCFUlxu8R .

0
评论操作 固定链接

Thank you for fixing this. I noticed there was a different project layout when I was referencing the gradle guide: https://guides.gradle.org/building-java-web-applications/  

When I try to create this sample gradle project, I get a stack trace when I run $ ./gradlew appRun

Is this the proper way to create the project?

 

0
评论操作 固定链接

Yes, it will create a project with the correct layout. For running it on the app server from the command line Gradle you will need to add additional configuration to build.gradle, but it's outside of the IntelliJ IDEA support scope.

0
评论操作 固定链接

I am facing an issue when I am calling the servlet page via index.jsp and when I jump from index.jsp to a servlet page which I had created. The browser shows 404 /servlet not found. I am stuck at this and trying everything possible but anything is not working. Please provide any feasible solution to this problem.

0
评论操作 固定链接

2020_07_21_VYfSrrhQPoqWJS3w  I have uploaded it on the following id

 

0
评论操作 固定链接

Your project works fine with Tomcat 9 on my system:

0
评论操作 固定链接

Then what is the issue in mine system

0
评论操作 固定链接

Not sure, upload the full log from the run console when using Tomcat 9 and a short video showing how you run it and what results you get in the browser.

0
评论操作 固定链接

When I am running the following code I am getting 404 error always

 

0
评论操作 固定链接

You are not following the suggestions and running unreleased Tomcat 10, I specifically asked to try with Tomcat 9 release instead.

0
评论操作 固定链接

But It was not executing via use of tomcat 9 at first place but now the issue has been resolved. Thanks for your help

 

0
评论操作 固定链接

Hi there, I create Java Enterprise project and than I create Servlet class I want to run it, but I can't . How to solve this problem? is there any way which solve this problem?

0
评论操作 固定链接

>I want to run it, but I can't 

What exactly are you trying? What does not work?

Please follow this tutorial: Deploy a Java web application inside a Tomcat server container.

Also answered here https://stackoverflow.com/a/67770765/2000323

-1
评论操作 固定链接

Andrey Dernov sir, I just want to run Servlet class, but it has only run index.jsp.

0
评论操作 固定链接

I think this problem shouldn't have been that difficult.) You can very easily create web project of Servlet class and run it, but Intellij doesn't support.

0

请先登录再写评论。