On 18/05/2016 04:25, Kiran Badi wrote:
> Hi ,
>
> I have this link in jsp which has below tags,
>
> <%@page contentType="text/html" pageEncoding="UTF-8"%>
>
> <a href="TestServlet?teststring=testing&testing1">Testing</a>
>
> and then my servlet looks like below,
>
> /*
> * To change this license header, choose License Headers in Project
> Properties.
> * To change this template file, choose Tools | Templates
> * and open the template in the editor.
> */
> package controller;
>
> import java.io.IOException;
> import java.io.PrintWriter;
> import javax.servlet.ServletException;
> import javax.servlet.annotation.WebServlet;
> import javax.servlet.http.HttpServlet;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
>
> /**
> *
> * @author Kiran
> */
> @WebServlet(name = "TestServlet", urlPatterns = {"/TestServlet"})
> public class TestServlet extends HttpServlet {
>
> /**
> * Processes requests for both HTTP <code>GET</code> and
> <code>POST</code>
> * methods.
> *
> * @param request servlet request
> * @param response servlet response
> * @throws ServletException if a servlet-specific error occurs
> * @throws IOException if an I/O error occurs
> */
> protected void processRequest(HttpServletRequest request,
> HttpServletResponse response)
> throws ServletException, IOException {
> response.setContentType("text/html;charset=UTF-8");
> try (PrintWriter out = response.getWriter()) {
> /* TODO output your page here. You may use following sample
> code. */
> String param = request.getParameter("teststring");
> String param1 = new
> String(request.getParameter("teststring").getBytes("UTF-8"));
> out.println("<!DOCTYPE html>");
> out.println("<html>");
> out.println("<head>");
> out.println("<title>Servlet TestServlet</title>");
> out.println("</head>");
> out.println("<body>");
> out.println("<h1>Servlet TestServlet at " +
> request.getContextPath() + "</h1>");
> out.println("<h1>Servlet TestServlet at " + param + "</h1>");
> out.println("<h1>Servlet TestServlet at " + param1 + "</h1>");
> out.println("</body>");
> out.println("</html>");
> }
> }
>
> // <editor-fold defaultstate="collapsed" desc="HttpServlet methods.
> Click on the + sign on the left to edit the code.">
> /**
> * Handles the HTTP <code>GET</code> method.
> *
> * @param request servlet request
> * @param response servlet response
> * @throws ServletException if a servlet-specific error occurs
> * @throws IOException if an I/O error occurs
> */
> @Override
> protected void doGet(HttpServletRequest request, HttpServletResponse
> response)
> throws ServletException, IOException {
> processRequest(request, response);
> }
>
> /**
> * Handles the HTTP <code>POST</code> method.
> *
> * @param request servlet request
> * @param response servlet response
> * @throws ServletException if a servlet-specific error occurs
> * @throws IOException if an I/O error occurs
> */
> @Override
> protected void doPost(HttpServletRequest request, HttpServletResponse
> response)
> throws ServletException, IOException {
> processRequest(request, response);
> }
>
> }
>
> and getParameter for some reason seems to truncating the value after &
>
> Servlet TestServlet at testingServlet TestServlet at testing
>
> I really need to understand as what characters are accepted and what
> characters get truncated with getParameter.
>
> I am building few links on the fly which might have space,backslashes,
> comma and & characters in it.So wanted to understand should I encode it via
> js or container can take care of those for me.
https://tools.ietf.org/html/rfc3986
https://www.w3.org/TR/REC-html40/interact/forms.html#form-data-set
Keep in mind that there are multiple levels of encoding here. You may
need to encode some characters for use in a JSP as well.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]