我正在做一个健身房管理项目,其中我使用React作为前端和后端与Java EE,但不能理解如何连接这两个页面。我的前端页面有一个名为Register now的按钮,我希望当我单击该按钮时,jsp页面应该是打开的。
发布于 2021-01-15 02:26:15
从你的解释来看,实际上并不清楚你想要做什么。但是如果你想在点击按钮后直接转到.jsp页面,那么你可以直接写
<form action="page_name.jsp">
<button>click</button>
</form>或者,您可以从那里调用servlet类,也可以通过RequestDispatcher调用jsp。喜欢
<form action="/add">
<button>click</button>
</form>@WebServlet("/add")
public class AddServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
RequestDispatcher view = request.getRequestDispatcher("/add.jsp");
view.forward(request, response);
}
}发布于 2021-01-13 20:25:56
您可以在您的控制器中定义一个路由,或者示例get("/register"),如果它匹配,那么您将执行您的逻辑并交付您想要返回的页面
https://stackoverflow.com/questions/65701786
复制相似问题