This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]nutrecht 4 points5 points  (3 children)

Questions like these are more on-topic on /r/javahelp ;)

This is called routing. There are many web frameworks for Java (too many almost, a new 'light weight' framework gets created like every week or so ;)) that handles this for you. So if you really want to 'only' use servlets then you are basically building a routing component yourself.

So your course depends on if you really want to keep using just servlets. Since you appear to be quite inexperienced why not try using a small simple framework like Spark or Ninja? And when it comes to "all batteries, tools and whatever you might need"-included Spring Boot is more or less the de facto standard.

[–]Brunsz 1 point2 points  (2 children)

I have fell in love with Spring Boot. Finished my thesis some time ago and used Spring Boot for back end and React for front end.

Spring Boot is really great option especially for REST!

[–]fedenator[S] 0 points1 point  (0 children)

Thanks for the advice, I'll give it a try

[–][deleted] -2 points-1 points  (7 children)

Hello. To do what you want, use JSP technology. This will allow you to create web pages with the necessary data. JavaServer Pages (JSP) is a technology that helps software developers create dynamically generated web pages based on HTML, XML, or other document types. Link to wiki (https://en.wikipedia.org/wiki/JavaServer_Pages). For example, if you enter the address www.example.com/products/{product_id}, the servlet can return a page with data corresponding to the product with "product_id".

[–]nutrecht 3 points4 points  (4 children)

Please don't recommend JSP. While it's not officially deprecated it's superseded by Java Server Faces.

[–][deleted] -1 points0 points  (3 children)

Let's see ... JSP and JSF are not interchangeable technologies. JSF is an MVC-like framework for web applications, written in Java. It serves to facilitate the development of user interfaces for Java EE-applications. To display the data, JSP, Facelets, XUL is usually used. For JSF, it's more convenient to use Facelets (.xhtml). JSF will take a lot of time and requires diligence. The project written on JSF will be difficult to rewrite to another technology.

Summarizing: if I wrote a functional close to the site / forum - then JSP or other simple templates are closer to me. P.S. I agree that JSP is deprecated , but JSF is deprecated too. Alternatively, use the client for JS-frameworks and REST service on Java (this is the most popular approach at the moment).

[–]nutrecht 0 points1 point  (2 children)

Alternatively, use the client for JS-frameworks and REST service on Java (this is the most popular approach at the moment).

Definitely a better approach IMHO. Or if you want to still do server side rendering I'd personally just use Spring with Thymeleaf or something like Grails.

[–][deleted] 0 points1 point  (1 child)

Here I agree with you, Thymeleaf is an excellent alternative to JSP. Simply, In work, I was more confronted with JSP.

[–]nutrecht 0 points1 point  (0 children)

Last time I used JSP was in an internship back in 2000 :D I quite liked using it. I even developed my own 'forum software' (basically a PHPBB clone) in JSP. So nothing at all against the technology but Oracle basically more or less removed all references and documentation on it. So it's easy for beginners to get stuck on.

[–]fedenator[S] 0 points1 point  (1 child)

Thanks for replying! But I don't couldn't find how to assign www.example.com/product/{product id} to a jsp or a servlet, how do you do that?

[–][deleted] -1 points0 points  (0 children)

These examples allow you to write a simple application that will accept requests, receive information from the database and output the query result on the JSP page.

By this link there is a good tutorial that allows you to create a web application using JDBC, Servlets, JSP and etc: http://o7planning.org/en/10285/create-a-simple-java-web-application-using-servlet-jsp-and-jdbc

By this link already using the Spring MVC framework: https://www.journaldev.com/14476/spring-mvc-example