簡體   English   中英

Java將servlet請求設置到jsp頁面

[英]Java set servlet request into jsp page

我必須將一些值從servlet加載到jsp頁面

我的“ order_processing.jsp” JSP頁面代碼如下所示

<%@page import="test.abc.io.User_Objects"%>
<%@ page import="java.util.Date" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Order Processing</title>
</head>
<body>
    <form name="OrderProcessing" action="order_processing" method="post" onsubmit="return validateForm();">
        <table align="center">
            <tr align="center">
                <td colspan="2">
                    <img src="images/otn_logo.jpg"/>
                </td>
            </tr>
            <tr>
                <td>First Name :</td>
                <td><input type="text" id="txtFirstname" name="txtFirstname" value="${reqObj.firstname}" /></td>
            </tr>
            <tr>
                <td>Last Name :</td>
                <td><input type="text" id="txtLastname" name="txtLastname" value="${reqObj.lastname}" /></td>
            </tr>
            <tr>
                <td>Communication Email :</td>
                <td><input type="text" id="txtCommunicationEmail" name="txtCommunicationEmail" value="${reqObj.commEmail}" />
                <label style="color: red;">*</label></td>
            </tr>
            <tr align="left">
                <td colspan="2"><input type="submit" value="Submit" /></td>
            </tr>
        </table>
    </form>
</body>
</html>

我的User_Objects代碼

public class User_Objects {
    public String firstname;
    public String lastname;
    public String commEmail;
}

我的“訂單處理”代碼

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class OrderProcessing extends HttpServlet {
    private static final long serialVersionUID = 1L;
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            User_Objects fillObj = new User_Objects();
            fillObj.firstname = "Test";
            fillObj.lastname = "User1";
            fillObj.commEmail = "tuser01@xyz.com";

            request.setAttribute("reqObj", fillObj);
            RequestDispatcher view = request.getRequestDispatcher("/order_processing.jsp");
            view.forward(request, response);
        } catch (Exception e) {
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        System.out.println("into OrderProcessing java");
    }
}

我的web.xml代碼

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>OrderProcessing</display-name>
  <welcome-file-list>
    <welcome-file>order_processing.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>order_processing</servlet-name>
    <servlet-class>test.abc.io.OrderProcessing</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>order_processing</servlet-name>
    <url-pattern>/order_processing</url-pattern>
  </servlet-mapping>
</web-app>

當我調試該項目並單擊Submit按鈕時,出現以下錯誤:

SEVERE: Servlet.service() for servlet jsp threw exception
javax.el.PropertyNotFoundException: Property 'firstname' not found on type test.abc.io.User_Objects

並且我還想在“ order_processing.jsp”頁面加載上執行一些任務。 但是,當我運行該項目時,我的order_processing.jsp頁面成功顯示,但是在這種情況下,我的OrderProcessing.java doGet方法沒有調用。

我在Eclipse Mars中使用JAVA。

對象“ User_Objects”不是Java Bean:名字,姓氏和commEMail是字段,而不是屬性。 嘗試為firstName,lastName和commEMail添加getter / setter

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM