JSP代码翻译问题

发布于 2024-10-20 10:15:26 字数 2163 浏览 2 评论 0原文

我的 JSP 转换(Servlet 到 JSP)遇到问题。

这是我的 JSP 代码:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<jsp:directive.page import="java.io.*" />
<jsp:directive.page import="javax.servlet.*" />
<jsp:directive.page import="javax.servlet.http.*" />
<jsp:directive.page import="Inventory.Item"/>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Display Data</title>
</head> 
<body>
    <jsp:useBean id="inventory" class="Inventory.AddData" />
    <%!public class DisplayData extends HttpServlet {

            public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
                    throws ServletException, IOException {

                response.setContentType("text/html");
                PrintWriter out = response.getWriter();
                Item item = (Item) request.getAttribute("invenItem");

                if (item != null) {
                    out.println("Stock ID  : " + item.getStockID() + "<br/>");
                    out.println("Name      : " + item.getItemName() + "<br/>");
                    out.println("Unit Price: " + item.getUnitPrice() + "<br/>");
                    out.println("On Stock  : " + item.getOnStock() + "<br/>");
                    out.println("</body>");
                    out.println("</html>");
                } else {
                    RequestDispatcher rd =
                            request.getRequestDispatcher("/SearchPage.html");
                    rd.include(request, response);
                    rd = request.getRequestDispatcher("/AddData.html");
                    rd.include(request, response);
                }
            }
        }%>
</body>

此代码取自 Servlet,该 Servlet 显示用户搜索的条目信息。

当我运行此 JSP 代码时,它会在我的 Web 服务器上打开一个新页面,但不显示任何内容,只是空白页面

据说这将显示用户搜索的条目的信息。请帮助...

首先...我做的JSP 翻译对吗?

I am having problem with my JSP conversion (Servlet to JSP).

this is my JSP code:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<jsp:directive.page import="java.io.*" />
<jsp:directive.page import="javax.servlet.*" />
<jsp:directive.page import="javax.servlet.http.*" />
<jsp:directive.page import="Inventory.Item"/>

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Display Data</title>
</head> 
<body>
    <jsp:useBean id="inventory" class="Inventory.AddData" />
    <%!public class DisplayData extends HttpServlet {

            public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
                    throws ServletException, IOException {

                response.setContentType("text/html");
                PrintWriter out = response.getWriter();
                Item item = (Item) request.getAttribute("invenItem");

                if (item != null) {
                    out.println("Stock ID  : " + item.getStockID() + "<br/>");
                    out.println("Name      : " + item.getItemName() + "<br/>");
                    out.println("Unit Price: " + item.getUnitPrice() + "<br/>");
                    out.println("On Stock  : " + item.getOnStock() + "<br/>");
                    out.println("</body>");
                    out.println("</html>");
                } else {
                    RequestDispatcher rd =
                            request.getRequestDispatcher("/SearchPage.html");
                    rd.include(request, response);
                    rd = request.getRequestDispatcher("/AddData.html");
                    rd.include(request, response);
                }
            }
        }%>
</body>

This code was taken from a Servlet which shows an Information of the Entry searched by a user.

When I run this JSP code it opens a new page on my web server but Doesn't Display Anything Just a Blank Page.

Supposedly this will show the Information of the entry searched by a user. Please Help...

In the first Place... Am I doing JSP translation right?

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

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

发布评论

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

评论(1

三生殊途 2024-10-27 10:15:26

在 JSP 中使用 Scriptlet 方法

  1. 通过执行以下操作导入对象项.. package.*

  2. 无需导入 java 包。

  3. 在正文上放置此代码。

     <% Item item = (Item) request.getAttribute("invenItem"); 
            if (item!= null) { %>;
    
               库存 ID :<%= item.getStockID() %>
    名称:<%= item.getItemName() %>
    单价:<%= item.getUnitPrice() %>
    库存:<%= item.getOnStock() %>
    <% } 其他 { %> <%@ 包含文件="DataForm.html" %>
    <%@ 包含文件="ItemEntry.html" %> <% } %>

有关说明,请按照 BalucC 先生的建议阅读此内容
然后尝试使用 javabean 和 EL 创建 JSP。

注意:您的代码中已经有一个 javabean.. view this 用于 javabean 和 EL 代码

Using the Scriptlets Method in JSP

  1. import the Object item by doing this.. package.*

  2. No need to import the java packages.

  3. On the body place this code instead.

         <% Item item = (Item) request.getAttribute("invenItem"); 
            if (item != null) { %>
    
               Stock ID  : <%= item.getStockID()  %><br>
               Name      : <%= item.getItemName() %><br>
               Unit Price: <%= item.getUnitPrice() %><br>
               On Stock  : <%= item.getOnStock() %><br>
    
         <%  } else {  %>
               <%@ include file ="DataForm.html" %><br>
               <%@ include file ="ItemEntry.html" %>
         <%  } %>
    

For the explanation, read this as per Mr BalucC's suggestion.
Then try also creating JSP using javabeans and EL.

Note: There's already a javabeans in your code.. <jsp:useBean id="inventory" class="Inventory.AddData" /> view this for the javabeans and EL code

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