Click here to Skip to main content
15,916,417 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am browsing a file on a jsp page and sending this file address to second jsp page, on second jsp page i am receiving this file path as a string the code is given below.
HTML
<%
String st=request.getParameter("mptest");
String rst=  request.getRealPath(st); 

\\here in rst i am geting a path as c:\vishal\ragh.xls and i wish to replace \ with \\ . Hence i used replace method for it the way given below

rst = rst.replace("\","\\"); 

\\but netbeans id showing an error that "illigal scape character" . Is there any other way so that
i could do my job.Please anyone help me.
    
%>
Posted
Updated 15-Aug-13 22:10pm
v2

Try
rst = rst.replace("\\","\\\\");

This[^] may help you.

[edit]four \es in the replacement string.[/edit]
 
Share this answer
 
v2
Comments
Maciej Los 16-Aug-13 6:16am    
Short and to the point!
+5!
Abhinav S 16-Aug-13 22:04pm    
Thank you.
it doesn't solve my problem...... when i used it , it remove the error but didn't give desired output my copmlete code is given below






XML
<%@page import="org.apache.poi.ss.usermodel.Cell"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.io.*"%>
<%@page import="java.util.regex.Matcher"%>
<%@page import="java.util.*"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%@page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
<form  action="tab.jsp" method="get" enctype="multipart/form-data>
            <div align="left">
                <input type="file" name="F1" > <br>
                <input type="submit" name="send">

<table border="1">
<% String rst=null;
    try
    {
  String st=request.getParameter("mptest");
  String o= Matcher.quoteReplacement("'\'");
   rst=  request.getRealPath(st);
  rst = rst.replace("\\","\\\\");
    out.println(rst);}
    catch(Exception e)
   {e.printStackTrace();}

    int i=0;
    String  value1="";
    double value2=0;
    if(rst != null && !rst.equals(""))
    {
    try
    {
    FileInputStream fs =new FileInputStream(rst);
    HSSFWorkbook wb = new HSSFWorkbook(fs);
    for(int k = 0; k < wb.getNumberOfSheets(); k++)
    {
    int j=i+1;
    HSSFSheet sheet = wb.getSheetAt(k);
    int rows  = sheet.getPhysicalNumberOfRows();
    for(int r = 0; r < rows; r++)
    {
    HSSFRow row   = sheet.getRow(r);
    %>
    <tr>
    <%

    int cells = row.getPhysicalNumberOfCells();
    for(int ce = 0; ce < cells; ce++)
    {

    HSSFCell cell1  = row.getCell(ce);
    switch(cell1.getCellType())
    {
        case Cell.CELL_TYPE_STRING:
     value1 = cell1.getStringCellValue();
   %>
   <td><%=value1%></td>
   <%
   break;
    case Cell.CELL_TYPE_NUMERIC:
     value2 = cell1.getNumericCellValue();
   %>
   <td><%=value2%></td>
   <%
  break;
    }

    %>

    <%
    }
    %>
    </tr>
    <%
        i++;
    }
        }
    }
    catch(Exception e){
    System.out.println(e);
    }
    }
    %>
    </table>
</form>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900