0
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<html>
<form action="index.jsp">
    <body>
        First INPUT:
        <input name="firstinput" type="text" name="fname">
        <br>
        <input type="submit" value="Submit">
        <%
            String first = request.getParameter("firstinput");
            out.println(first);
        %>
    </body>
</form>
</html>

This is my code when enter Hello then it print Hello and when enter "Hello", then it prints "Hello". In the later case, I want it should print Hello. How I will do this? Please tell me How I can remove ", if a user enters a quoted text?

4

2 回答 2

0

Replace with this,

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<html>
<form action="index.jsp">
    <body>
        First INPUT:
        <input name="firstinput" type="text" name="fname">
        <br>
        <input type="submit" value="Submit">
        <%
           String first = request.getParameter("firstinput");
           if(first!=null){

              String data=null;
              if(first.startsWith("\"") && first.endsWith("\"")){
                data = first.substring(1, first.length-1)
              }
              out.println(data );
         }

        %>
    </body>
</form>
</html>

do proper null check if i missed any.

于 2013-08-01T09:10:25.080 回答
0

Maybe this one

<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
...


<input type="submit" value="Submit">
<c:out value='${fn:replace(param.firstinput, "\"", " ")}'>
     no parameter 
</c:out>
于 2013-08-01T09:18:17.913 回答