Quantcast
Channel: Active questions tagged servlets - Stack Overflow
Viewing all articles
Browse latest Browse all 675

How to configure my servlet to listen on URL pattern of *.ajax

$
0
0

I am using a servlet which URL name is general. I send some form parameters to servlet and i will handle them in Java. But how to configure my servlet to send Ajax request like getRecords.ajax or getAnother.ajax. So namely, I want to send all *.ajax to my servlet.

And then i want to handle in my servlet like this;

public getAnother (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODOreturn JSONObject}

not in doGet.

And my servlet also like this (a sample servlet):

package com.domain;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletConfig;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;/** * Servlet implementation class General */@WebServlet("/General")public class General extends HttpServlet {    private static final long serialVersionUID = 1L;     private String message;    /**     * Default constructor.      */    public General() {        // TODO Auto-generated constructor stub    }    /**     * @see Servlet#init(ServletConfig)     */    public void init(ServletConfig config) throws ServletException {         message = "Hello World";    }    /**     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)     */    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {         // Set response content type          response.setContentType("text/html");          String colorName=request.getParameter("color");          // Actual logic goes here.          PrintWriter out = response.getWriter();          out.println("<h1>"+ message +"</h1>");          out.println("<br><h2>"+colorName+"</h2>");    }    /**     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)     */    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        // TODO Auto-generated method stub    }

Viewing all articles
Browse latest Browse all 675

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>