从JSP页面访问传递给servlet的变量值

时间:2016-05-01 03:12:48

标签: java jsp servlets

我正在做一个OCR系统,用户可以上传任何格式的图像。然后上传的图像显示在imageView.jsp页面内。 imageView.jsp

<div  id = "imageView" class="col-lg-8 center-block modal-content">
                    <form action="ImagePreprocess" method="post" class=" form" role="form" enctype="multipart/form-data">
                        <input type="submit" class= "btn btn-image pull-left" value="OCR">
                    </form>

                    <a href="home.jsp" class="btn btn-default bg-light-gray">Upload a new Image</a>

                </div>

            </div>
            <%
                String fname = (String) request.getAttribute("name");
            session.setAttribute("filename ", fname);
                fname = fname + ".jpg";
                String fnames = (String) request.getAttribute("images");
                request.getSession().setAttribute("bimla", fnames);
                System.out.println("fnames:"+fnames);
                System.out.print("uploaded image bbbbbbb"+fname);
                String path = "";
                if (request.getAttribute("name") != null) {
                    path = request.getAttribute("name").toString();
                }
              //  String filepath = application.getRealPath("/uploadedImage/");
               // System.out.println(filepath);


            %>

            <div class="row">
                <div  id = "display" class="col-lg-8 center-block modal-content">
                <img src='uploadedImage/<%=fname %>'width="600" height="400"/>
                   <input type="hidden" name="image" value="<%=fname %>" />
                </div>

imagePreprocess.jsp

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

            //System.out.println("bimla1");
            PrintWriter out = response.getWriter();
          HttpSession fileNameSession = request.getSession();
          //  String imageName = (String) fileNameSession.getAttribute("filename");
          //  String imageName = (String)request.getAttribute("filename");
         // String imageName =  (String) request.getSession().setAttribute("filename");
         //   System.out.println("i am bimlaaaaa"+imageName);

            //System.out.println("bimla2");
           String imageName = request.getParameter("image").toString();
          // String imageName =(String) fileNameSession.getAttribute("bimla");

            //System.out.println("bimla3");
            grayscaleClass grayImage = new grayscaleClass();

            //System.out.println("bimla4");
            imageUpload img = new imageUpload();
       //     String extn = img.getExtensn(imageName);

            //System.out.println("bimla5");
            File fileNme = new File(imageName);
            File outputGrayImage = grayImage.imagePreprocessing(imageName+"."+"jpg", "jpg");
            out.println(outputGrayImage);
            String grayImageName = outputGrayImage.getName();
}

变量的值在jsp页面中正确打印。但是当我尝试通过servlet页面加入变量值时,它会给出一个空值。我甚至在jsp页面中使用了隐藏字段。但它也给出了空值。我甚至使用过会话。它还给出null值。你有什么想法吗?

0 个答案:

没有答案