은 다음과 JSP를 고려JSP에서 잡은 값을 Servlet에 전달하는 방법은 무엇입니까?
package controller.client;
import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import db.DatabaseInventory;
/**
* Servlet implementation class Client1_before
*/
@WebServlet("/clientAction1")
public class Client1_inventory extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
HttpSession session = request.getSession();
synchronized(session)
{
String grabbedNameAndLastName = request.getParameter("nameAndLastName");
// do something with
// uncomment this code if you want to use a for loop
// ArrayList<String> inventory = null;
String inventoryStringVersion = null;
DatabaseInventory myDatabase = new DatabaseInventory();
try
{
myDatabase.initiateConnection(); // open connection
}
catch (ClassNotFoundException e1) {e1.printStackTrace();}
try
{
// uncomment this code if you want to use a for loop
// inventory = myDatabase.getInventoryProducts();
inventoryStringVersion = myDatabase.returnInventoryWholeString();
}
catch (SQLException e) {e.printStackTrace();}
// uncomment this code if you want to use a for loop
// request.setAttribute("inventoryList", inventory);
request.setAttribute("inventoryBigString", inventoryStringVersion);
// forwards to the page employeeOpenNewAccount.jsp
request.getRequestDispatcher("/WEB-INF/results/client"
+ "/client1_seeInventory.jsp").forward(request, response);
}
}
}
내가 내 서블릿을 하기 위해 JSP에서 필드 ${name.firstName}
및 ${name.lastName}
을 전달하려는 :
<!-- Client's Page - permissions -->
<!DOCTYPE html>
<html>
<head><title>Product Inventory Program</title>
<link rel="stylesheet"
href="./css/styles.css"
type="text/css"/>
<link rel="stylesheet"
href="./css/bar.css"
type="text/css"/>
</head>
<div id ="right" class="bar">
<a href="loggingOut">LOG-OUT</a>
</div>
<body>
<table class="title">
<tr><th>Client's page - Please choose one of the options below</th></tr>
</table>
<body>
<h1>Hello ${name.firstName} ${name.lastName} , You've logged in successfully!</h1>
<h1>
Please choose one of the following options
</h1>
<!-- Client Transactions -->
<fieldset>
<legend>View all the products in the store</legend>
<form action="blablabla">
<a href="clientAction1">Press here to continue</a>
</form>
</fieldset>
</body></html>
내가 clientAction1
라는 서블릿을 가지고있다.
어떻게하면됩니까?
우리가 숨겨진 입력을 사용할 수 있습니다 이것에 대한
* * "기존 필드"가 * 없습니다. JSP에서 서블릿으로 값을 전송하면됩니다. –
Dave는 정확합니다. 여기에있는 표준은 양식과 함께 제출하는 것입니다. 페이지에 이미 정적 값이있는 경우에는 숨겨진 입력 값이있을 수도 있습니다. –
@CraigOtis : 숨겨진 입력을 어떻게 만들 수 있습니까? – ron