Servlet 的参数传递问题

发布于 2024-12-28 07:28:33 字数 320 浏览 1 评论 0原文

我使用 NetBeans 6.9 创建了一个 Web 应用程序项目和 Java 应用程序项目。现在,我的项目结构就像,

Web Application Project 
    WEB-INF
        JSP Page
    Source Package
        Servlet

Java Application Project
     default package
             Java File

现在,我想将参数从 Servlet/JSP 传递到 Java 文件(双向)。谁能帮助我,我该如何解决这个问题?提前致谢。

I have created a Web Application Project and Java Application Project using NetBeans 6.9. Now, my project structure is like,

Web Application Project 
    WEB-INF
        JSP Page
    Source Package
        Servlet

Java Application Project
     default package
             Java File

Now, I want to pass parameters from Servlet/JSP to Java file (in both direction). Can anybody help me, how can I solve this ? Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荒岛晴空 2025-01-04 07:28:33

传递到 JSP/Servlet 的参数很可能通过请求参数(或者可能是会话参数)完成。这是在构造查询字符串时完成的。

例如;

/mywebapp/MyJsp.jsp?param1=param1Value¶m2=param2Value

在 Servlet 的情况下可以使用相同的查询字符串。 Servlet 只需要在 web.xml 中进行配置即可,这是通过
web.xml 中的 标记。

JSP 和 Servlet 文件都应该能够导入和引用您提到的默认包下的“Java 文件”的方法。假设 Java 文件位于类路径上(作为类文件或 JAR 文件),则可以直接调用类中的方法。

查看一些有关开发网络应用程序的介绍性教程,您很快就会获得一些有关这一切如何工作的示例。

Your parameter passing to the JSP/Servlet will most likely be done via request parameters (or possibly session parameters. This is done in the construction of your query string.

For example;

/mywebapp/MyJsp.jsp?param1=param1Value¶m2=param2Value

The same query strings can be used in the case of Servlets. The Servlets simply need to be configured in your web.xml This is done via the
<servlet> and <servlet-mapping> tags within the web.xml.

Both the JSP and Servlet files should be able to import and reference the methods of your "Java File" under the default pacakage that you mentioned. The can directly call methods in your classes assuming that the Java file is on your classpath (either as a class file or in a JAR file).

Take a look at some introductory tutorials on developing a web-app and you'll soon get some examples of how this all works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文