स्टैक ओवरफ्लो पर बहुत सारे शोध के बाद मैं इस प्रश्न को पोस्ट कर रहा हूं क्योंकि मुझे इस मुद्दे का समाधान नहीं मिला।स्ट्रूट 2- यूआरएल टैग - छुपाएं क्वेरी स्ट्रिंग
आवश्यकता परिदृश्य: प्रत्येक ग्राहक आईडी के आधार पर ग्राहकों की सूची से ग्राहक को एक पैरामीटर के रूप में अपडेट करें।
समाधान प्रयास किया गया: जेएसपी से प्राप्त ग्राहक आईडी के आधार पर, इसे स्ट्रूट 2 यूआरएल टैग के रूप में क्रिया में पास करें।
समस्या का सामना करना - URL पर दिखाई देने वाली क्वेरी स्ट्रिंग।
http://foo.com/Struts2Example/getCustomerAction?customerId=2
सवाल:
- हम नहीं क्वेरी स्ट्रिंग को छिपाने कर सकते हैं अगर हम struts यूआरएल टैग का उपयोग?
- यदि हम यूआरएल टैग का उपयोग करते समय उपयोग क्वेरी स्ट्रिंग को छिपा नहीं सकते हैं? उपरोक्त परिदृश्य के लिए विकल्प क्या है।
struts.xml, jsp और नीचे कार्रवाई के लिए कोड -
<h2>All Customers Details</h2>
<s:if test="customerList.size() > 0">
<table border="1px" cellpadding="8px">
<tr>
<th>Customer Id</th>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
<th>Created Date</th>
</tr>
<s:iterator value="customerList" status="userStatus">
<tr>
<td><s:url var="editCustomer" action="getCustomerAction">
<s:param name="customerId" value="%{customerId}" />
</s:url>
<p>
<s:a href="%{editCustomer}">
<s:property value="customerId" />
</s:a>
</p></td>
<td><s:property value="firstname" /></td>
<td><s:property value="lastname" /></td>
<td><s:property value="age" /></td>
<td><s:date name="createdDate" format="dd/MM/yyyy" /></td>
</tr>
</s:iterator>
</table>
</s:if>
<br />
<br />
struts.xml-
<!-- Get Customer Details - To Pre-Populate the form to update a Customer -->
<action name="getCustomerAction" method="getCustomerById"
class="com.hcl.customer.action.CustomerAction">
<result name="success">pages/customerForm.jsp </result>
</action>
ग्राहक कार्रवाई कक्षा
public class CustomerAction extends ActionSupport implements ModelDriven {
Logger logger = Logger.getLogger(CustomerAction.class);
Customer customer = new Customer();
List<Customer> customerList = new ArrayList<Customer>();
CustomerDAO customerDAO = new CustomerDAOImpl();
public Customer getCustomer() {
return customer;
}
//Set Customer onto Value Stack
public void setCustomer(Customer customer) {
this.customer = customer;
}
public List<Customer> getCustomerList() {
return customerList;
}
//Set Customer List onto Value Stack
public void setCustomerList(List<Customer> customerList) {
this.customerList = customerList;
}
public String execute() throws Exception {
return SUCCESS;
}
public Object getModel() {
return customer;
}
// Edit customer details, it will retrieve the records based on customerId
//SkipValidation is used to skip the validate()
@SkipValidation
public String getCustomerById() {
logger.info("** Customer Id to edit ** " + customer.getCustomerId());
customer = customerDAO.customerById(customer.getCustomerId());
return SUCCESS;
}
क्यों आप आईडी को छिपाना चाहते हैं? यदि आप ग्राहक पक्ष पर मूल्य संग्रहीत करते हैं तो कोई भी स्रोत को देख सकता है और इसे प्राप्त कर सकता है। परिणाम देखने के लिए आप निश्चित रूप से पोस्ट का उपयोग कर सकते हैं, हालांकि उपयोगकर्ता को पृष्ठ को बुकमार्क करने की आवश्यकता पर विचार करें। वास्तव में जवाब सुरक्षा है ... क्या यह उपयोगकर्ता इस ग्राहक आईडी तक पहुंचने में सक्षम होना चाहिए? यदि नहीं तो किसी भी मामले में इसकी अनुमति नहीं दी जानी चाहिए। – Quaternion
हाँ उपयोगकर्ता इस तरह के एक पेज को बुकमार्क कर सकता है ... लेकिन सवाल कहता है कि यूआरएल '** ग्राहक को अपडेट करें '** प्राप्त करें ग्राहक ** कार्य? ग्राहक आईडी = 2' ... यहां कुछ अजीब बात है:> –
@AndreaLigios - परिदृश्य है, एक ग्राहक को अद्यतन करने के लिए, मुझे फॉर्म पर अपने विवरण पूर्व-पॉप्युलेट करना होगा। विवरण लाने के लिए, मैं ग्राहक आईडी के साथ डेटाबेस से पूछता हूं। –