简体   繁体   English

将信息从Servlet发送到JSP

[英]Sending Information from a Servlet to a JSP

ok this is what I'm trying to do...I have 1 JSP page that gets 2 integers from a user. 好的,这就是我想要做的...我有1个JSP页面,该页面从用户那里获取2个整数。 I use a form in this JSP so I can send the information to the servlet with the doGet method. 我在此JSP中使用表单,因此可以使用doGet方法将信息发送到servlet。

Then I want to take those numbers find the greatest common denominator and send that to another JSP. 然后,我想利用这些数字找到最大的公分母,并将其发送给另一个JSP。 Getting the GCD isnt the issue right now, I'll just use function. 现在获取GCD并不是问题,我将仅使用function。 But I cant figure out how to send anything to a new JSP. 但是我不知道如何将任何东西发送到新的JSP。

    request.setAttribute("TEST", "TESTING");
    request.getRequestDispatcher("/WEB-INF/JSP2.jsp").forward(request, response);

Thats what I was playing around with to send information from the servlet to another JSP called JSP2. 那就是我正在努力将信息从servlet发送到另一个称为JSP2的JSP的过程。 but whenever I hit submit on JSP (where I enter the numbers) I get an error. 但是,每当我在JSP上单击“提交”(在其中输入数字)时,都会收到错误消息。

Any help will be greatly appreciated 任何帮助将不胜感激

Show us the directory structure of your project. 向我们展示您项目的目录结构。 Make an index.jsp page saying hello and see if you can access it. 制作一个index.jsp页面打招呼,看看是否可以访问它。

How do you deploy the application, show us the .war unzipped contents. 如何部署应用程序,向我们展示.war解压缩的内容。

Your idea to use the requestDispatcher is correct, as well as adding stuff to the request, and later in another servlet/jsp using them. 您使用requestDispatcher的想法是正确的,并且向请求中添加了内容,后来在另一个使用它们的servlet / jsp中使用了。 Note that if you access the index.jsp by server:port/index.jsp then the requestDispatcher argument should also be "your.jsp" and not "WEB-INF/the.jsp", ie remove the WEB-INF. 请注意,如果通过server:port / index.jsp访问index.jsp,则requestDispatcher参数也应该是“ your.jsp”,而不是“ WEB-INF / the.jsp”,即删除WEB-INF。

如果您的表单正在POST到servlet,您是否应该实现doPost而不是doGet

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM