JSP代码翻译问题
我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 JSP 中使用 Scriptlet 方法
通过执行以下操作导入对象项.. package.*
无需导入 java 包。
在正文上放置此代码。
有关说明,请按照 BalucC 先生的建议阅读此内容。
然后尝试使用 javabean 和 EL 创建 JSP。
注意:您的代码中已经有一个 javabean..
view this 用于 javabean 和 EL 代码Using the Scriptlets Method in JSP
import the Object item by doing this.. package.*
No need to import the java packages.
On the body place this code instead.
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