2012-01-01 3 views
0

사용자 인터페이스에서 입력 한 항목을 기반으로 텍스트 파일을 채우려는 애플리케이션이 있습니다. Struts1을 선택 했으므로 대부분의 기능을 완료 할 수있었습니다. 그러나 텍스트 파일을 채우기를 유지하는 부분은 JSP의 사용자 항목을 기준으로 제가 고심하고있는 것입니다. 상기 SCANDATA 입력 후 http://www.image-share.com/ijpg-1178-105.html 3.'Submit 'PAGE1 항목에 기초하여 스캔 데이터 http://www.image-share.com/ijpg-1178-104.html 2.'Ask'사용자 인터페이스 페이지의 흐름request.getAttribute 값을 사용하여 JSP를 다시로드하는 방법

1.'Accept 사용자 항목은 다음과. 'http://www.image-share.com/ijpg-1178-106.html (세션 변수를 통해 이미지의 null 값을 교정 할 수있었습니다 .Dave에게 감사합니다.) 메시지는이 유효성 검사와 같은 null 항목과 함께 표시됩니다. 내 질문 : 사용자가 2 페이지의 스캔 데이터를 입력하고 동일한 JSP로 폴백하여 개 더 많은 스캔 데이터 값을 입력 할 수있는 시나리오가 있도록하기 위해 사용해야하는 것은 무엇입니까? 단추 클릭시 JavaScript 을 사용하여 페이지를 다시로드하는 방법을 생각하고있었습니다. 올바른 접근 방식입니까?

이에 대한 관련 코드는

<html:form action="txtwriter">  
    <% String itemname = (String)session.getAttribute("itemname"); %> 
<% String lotnumber = (String)session.getAttribute("lotnumber"); %> 
<% String godownname = (String)session.getAttribute("godownname"); %> 
<br/> 
<% String message = (String)session.getAttribute("message");  
session.setAttribute("theFileName", message); %> 
    Filename : <%= message %> 
<br/> Item Name :<%= itemname %> 
    <br/> Lot Number :<%= lotnumber %> 
    <br/> Godown Name :<%= godownname %> 
<br/> <bean:message key="label.scandata"/> 
<html:text property="scanData" ></html:text>  
<html:errors property="scanData"/> 
<br/>  
<html:submit/> 
    /* How should the submit button handle the onClick event so that when the users click 
    after entering the text. 
1. The entered text must be populated in the text file using a different action class. (I have this part working) 
    2.They must be on the same jsp with the scanData text box cleared waiting for the next user  entry into that text 
box so that this subsequest entry can also be entered into the text file. 
Is there a way i can empty the 'scanData' textbox by accessing it by name inside my action so that i can empty it from my action class? 
(I am looking for this  answer) 

*/


내가 LoginAction.java

HttpSession session = request.getSession(); 
session.setAttribute("message", textFile); 
session.setAttribute("itemname",loginForm.getItemName().trim()); 
session.setAttribute("lotnumber",loginForm.getLotNumber().trim());  
session.setAttribute("godownname",loginForm.getStockGodown().trim());  
+0

'TextWriter.java'는 동작 클래스가 아니며 양식입니다. 그것은 그것이 어떻게 관련되어 있는지 불분명합니다. –

+0

솔직히이 모든 것을 처리하는 것은 꽤 어렵습니다. 근본적인 문제가 무엇인지 완전히 명확하지 않습니다. –

+0

@DaveNewton 미안하다 실수를 지적 해 주신 데이브에게 감사드립니다. 지금 정확한 액션 클래스를 추가했습니다. 나는 당신이 지금 내가 제공 한 스크린 프린트를 보는 것을 corellate 할 수 있기를 바랍니다. 당신이 명확한 질문을하기 위해 필요한 것에 관해서 나를 안내해주십시오. –

답변

0

(안 대답 내부에서이를 사용, 리팩토링하지만, 도움을 얻으려는 다른 사용자를위한 테스트되지 않은 코드)

리팩토링 된 액션으로 실제 진행 상황을보다 쉽게 ​​확인할 수 있습니다. 원래의 코드는 추론하기가 어렵습니다. trim() 기능은 중복을 피하기 위해 작업 양식 설정자로 이동합니다.

public class LoginAction extends Action { 

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 
      throws Exception { 
     LoginForm loginForm = (LoginForm) form; 
     if (invalidForm(loginForm)) { 
      return mapping.findForward("failure"); 
     } 

     String fileName = createFile(loginForm); 

     request.setAttribute("message", fileName); 
     request.setAttribute("itemname", loginForm.getItemName()); 
     request.setAttribute("lotnumber", loginForm.getLotNumber()); 
     request.setAttribute("godownname", loginForm.getStockGodown()); 

     return mapping.findForward("success"); 
    } 

    private String createFile(LoginForm loginForm) throws IOException { 
     ServletContext context = getServlet().getServletContext(); 
     String driveName = context.getInitParameter("drive").trim(); 
     String folderName = context.getInitParameter("foldername").trim(); 

     String pathName = driveName + ":/" + folderName; 
     new File(pathName).mkdirs(); 

     String fileNamePath = pathName + createFileName(loginForm); 
     ensureFileExists(fileNamePath); 

     return fileNamePath; 
    } 

    private void ensureFileExists(String fileNamePath) throws IOException { 
     boolean fileExists = new File(fileNamePath).exists(); 
     if (!fileExists) { 
      File file = new File(fileNamePath); 
      file.createNewFile(); 
     } 
    } 

    private boolean invalidForm(LoginForm loginForm) { 
     return loginForm.getItemName().equals("") 
       || loginForm.getLotNumber().equals("") 
       || loginForm.getStockGodown().equals(""); 
    } 

    private String createFileName(LoginForm loginForm) { 
     return loginForm.getItemName() + "_" 
       + loginForm.getLotNumber() + "_" 
       + loginForm.getStockGodown() + "_" 
       + createFileNameTimeStamp() + ".txt"; 
    } 

    private String createFileNameTimeStamp() { 
     SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd G 'at' hh.mm.ss z"); 
     String dateTime = sdf.format(Calendar.getInstance().getTime()); 
     String[] tempDateStore = dateTime.split("AD at"); 
     return tempDateStore[0].trim() + "_" + tempDateStore[1].trim(); 
    } 

} 
관련 문제