Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that the Java Web project cannot access the html file?

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to solve if the Java Web project cannot access the html file". In the operation of the actual case, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Trampling problem and cause trampling problem

Because the blogger's JavaWeb is quick, so he is not very familiar with some knowledge points, so there is today's problem-Tomcat can not access the html file.

There is always a 404 in operation. Every time this happens, it's annoying and confusing. Although this problem does not have a great impact on some projects, it will make my project catalogue very messy. In general, the problem is that if you don't solve it, there will be a bunch of static resources in one folder. This may lead to a long time to find some project files at a later stage.

The cause of stepping on the pit

Because of carelessness, I put some html files under WEB-INF. Because the resources under WEB-INF cannot be accessed directly (WEB-INF is the web application security directory of Java, which is only open to the server and invisible to the client. Can only be requested and forwarded So it is not accessible on the browser (and redirection is not allowed).

Solution.

As mentioned above, direct access is not available. But we can access the html file by forwarding and requesting. In this project, the blogger is using the request for access. In other words, the front end sends a signal to the back end-indicating that I need to request a web page. Then the back end reacts accordingly and then returns to the corresponding interface.

Public class regist extends ssm.ViewBaseServlet {/ / inherits a class that is used to parse html. @ Override protected void doGet (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {super.processTemplate ("/ user/regist", req,resp); / / calls the method of the class. In fact, this place can choose to forward it more conveniently! }

Configuration of web.xml:

Jump database.jump jump / jump

Or add a @ WebServlet ("/ login") to the Java file.

Of course, we can also put static resources outside WEB-INF at the same level as static. Generally, we need to use `interceptor / filter to verify permissions and determine legitimate users.

This is the end of the content of "how to solve if the Java Web project cannot access the html file". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report