Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8506083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:29:59+00:00 2026-06-11T02:29:59+00:00

I have a jsp file that is displaying some records from the datastore, and

  • 0

I have a jsp file that is displaying some records from the datastore, and I want to have a delete button next to each entry that would remove it from the db.

So, I know that the Servelet will do the actual deleting, but I’m not sure what to put with the delete button in the jsp, so that my Servlet knows what entity (item) to look up in the database.

Is there a better way to do this?

Here is my jsp. Look down near the bottom where I have my delete button:

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="com.google.appengine.api.datastore.DatastoreServiceFactory" %>
<%@ page import="com.google.appengine.api.datastore.DatastoreService" %>
<%@ page import="com.google.appengine.api.datastore.Query" %>
<%@ page import="com.google.appengine.api.datastore.Entity" %>
<%@ page import="com.google.appengine.api.datastore.FetchOptions" %>
<%@ page import="com.google.appengine.api.datastore.Key" %>
<%@ page import="com.google.appengine.api.datastore.KeyFactory" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<html>
  <head>
    <link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
  </head>

  <body>

<%
    String podlistName = request.getParameter("podlistName");
    if (podlistName == null) {
        podlistName = "default";
    }
    pageContext.setAttribute("podlistName", podlistName);
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user != null) {
      pageContext.setAttribute("user", user);

%>
<p>Hello, ${fn:escapeXml(user.nickname)}! (You can
<a href="<%= userService.createLogoutURL(request.getRequestURI()) %>">sign out</a>.)</p>
<%
    } else {
%>
<p>Hello!
<a href="<%= userService.createLoginURL(request.getRequestURI()) %>">Sign in</a>
to include your name with podcasts you post.</p>
<%
    }
%>

<%
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    Key podlistKey = KeyFactory.createKey("Podlist", podlistName);
    // Run an ancestor query to ensure we see the most up-to-date
    // view of the Greetings belonging to the selected Podlist.
    Query query = new Query("Podcast", podlistKey).addSort("date", Query.SortDirection.DESCENDING);
    List<Entity> podcasts = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(5));
    if (podcasts.isEmpty()) {
        %>
        <p>Podlist '${fn:escapeXml(podlistName)}' has no items.</p>
        <%
    } else {
        %>
        <p>Items in Podlist '${fn:escapeXml(podlistName)}'.</p>
        <%
        for (Entity podcast : podcasts) {
            pageContext.setAttribute("podcast_url",
                                     podcast.getProperty("podcast_url"));
            if (podcast.getProperty("user") == null) {
                %>
                <p>An anonymous person wrote:</p>
                <%
            } else {
                pageContext.setAttribute("podcast_user",
                                         podcast.getProperty("user"));
                %>
                <p><b>${fn:escapeXml(podcast_user.nickname)}</b> wrote:</p>
                <%
            }
            %>
            <blockquote>${fn:escapeXml(podcast_url)}</blockquote>
            <form action="/delete" method="post">
              <div><input type="submit" value="Delete Podcast" /></div>
              <input type="hidden" name="podlistName" value="${fn:escapeXml(podlistName)}"/>
              <!-- not sure what to put here to give a reference to this entity-->
              <input type="hidden" name="podcast_id" value="$??"/>
            </form>
            <%
        }
    }
%>

    <form action="/add" method="post">
      <div><textarea name="podcast_url" rows="3" cols="60"></textarea></div>
      <div><input type="submit" value="Post Podcast" /></div>
      <input type="hidden" name="podlistName" value="${fn:escapeXml(podlistName)}"/>
    </form>

  </body>
</html>

Here is my Servlet:

package com.aol.sharepodder;

import java.io.IOException;
import java.util.Date;
import java.util.UUID;
import java.util.logging.Logger;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class AddPodcastServlet extends HttpServlet {
    private static final Logger log = Logger.getLogger(AddPodcastServlet.class.getName());

    public void doPost(HttpServletRequest req, HttpServletResponse resp)
                throws IOException {
        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();

        String podlistName = req.getParameter("podlistName");
        Key podlistKey = KeyFactory.createKey("Podlist", podlistName);
        String podcast_url = req.getParameter("podcast_url");
        Date date = new Date();
        Entity podcast = new Entity("Podcast", podlistKey);
        podcast.setProperty("user", user);
        podcast.setProperty("date", date);
        podcast.setProperty("podcast_url", podcast_url);

        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        datastore.put(podcast);

        resp.sendRedirect("/podlist.jsp?podlistName=" + podlistName);
    }
}

thanks!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:30:01+00:00Added an answer on June 11, 2026 at 2:30 am

    It seems like you are already making use of a “podcast_id” – so then why don’t you pass that in the request to the /delete handler?

    podcast.getProperty("podcast_id")
    

    Seems hard for us to tell you what you need to pass as it is your application – but what you probably want is to pass a parameter that uniquely refers to the entity (whether that be a “key”, “podcast_id”, etc). Each entity in GAE has a unique key.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page in JSP that list some file that could be downloaded
I have created a simple JSP file that I want to deploy in Jetty
I have a jsp file that generates some files at runtime, which are also
I have list of images in my jsp file that i want to display
I have a .jsp file that receives a request and checks the request's parameters.
so i have a .js file that 2 different jsp pages call. .js file
I have hard-coded data into a .jsp file. What I want to do is
Suppose I have a JSP file that contains a tag (hence a .tag file).
let's say i have a servlet that forwards a request to a jsp file
I have a .csv file that needs to be read for my jsp. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.