hi i have developed an application and when iam trying to access the
application through  url request from browser iam getting thesome
error

my application code is as follows
 classes for my app

Counter.java

/* Copyright (c) 2009 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.appengine.demos.taskqueueexamples;

import javax.jdo.JDOObjectNotFoundException;
import javax.jdo.PersistenceManager;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

/**
 * A JDO object representing a counter.
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Counter {

  @PrimaryKey
  private String name;

  @Persistent
  private int count;

  public Counter(String name, int count) {
    this.name = name;
    this.count = count;
  }

  public String getName() {
    return name;
  }

  public int getCount() {
    return count;
  }

  public void increment(int delta) {
    count += delta;
  }

  /* Helper methods */

  public static void createOrIncrement(String name, int delta) {
    PersistenceManager pm = PMF.get().getPersistenceManager();
    Counter counter = null;
    try {
      pm.currentTransaction().begin();
      try {
        counter = pm.getObjectById(Counter.class, name);
        counter.increment(delta);
      } catch (JDOObjectNotFoundException e) {
        counter = new Counter(name, delta);
        pm.makePersistent(counter);
      }
      pm.currentTransaction().commit();
    } finally {
      if (pm.currentTransaction().isActive()) {
        pm.currentTransaction().rollback();
      }
    }
  }

  public static int getCount(String name) {
    PersistenceManager pm = PMF.get().getPersistenceManager();
    Counter counter = null;
    try {
      counter = pm.getObjectById(Counter.class, name);
    } catch (JDOObjectNotFoundException e) {
    }
    if (counter == null) {
      return 0;
    } else {
      return counter.getCount();
    }
  }
}


PMF.java


/* Copyright (c) 2009 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.appengine.demos.taskqueueexamples;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManagerFactory;

public final class PMF {
  private static final PersistenceManagerFactory pmfInstance =
      JDOHelper.getPersistenceManagerFactory("transactions-optional");

  private PMF() {}

  public static PersistenceManagerFactory get() {
    return pmfInstance;
  }
}

SimpleCounterWork.java

/* Copyright (c) 2009 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.appengine.demos.taskqueueexamples;

import java.io.IOException;

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

/**
 * Task Queue worker servlet that offsets a counter by a delta.
 */
public class SimpleCounterWork extends HttpServlet {
  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {
    Counter.createOrIncrement(
        req.getParameter("name"),
        Integer.parseInt(req.getParameter("delta")));
  }
}


SimpleServletCounterServlet.Java

/* Copyright (c) 2009 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.appengine.demos.taskqueueexamples;


import com.google.appengine.api.labs.taskqueue.QueueFactory;
import com.google.appengine.api.labs.taskqueue.TaskOptions;

import java.io.IOException;

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

/**
 * Servlet that schedules a counter to be increased.
 */
public class SimpleServletCounterServlet extends HttpServlet {
  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {


    resp.sendRedirect("/simplecounter.jsp");
  }
}


Web.xml


<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns="http://java.sun.com/xml/ns/javaee";
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"; version="2.5">
        <servlet>
                
<servlet-name>com.google.appengine.demos.taskqueueexamples</servlet-
name>
                <servlet-
class>com.google.appengine.demos.taskqueueexamples.SimpleServletCounterServlet</
servlet-class>
        </servlet>
        <servlet-mapping>
                
<servlet-name>com.google.appengine.demos.taskqueueexamples</servlet-
name>
                <url-pattern>/com.google.appengine.demos.taskqueueexamples</url-
pattern>
        </servlet-mapping>
        <welcome-file-list>
                <welcome-file>index.html</welcome-file>
        </welcome-file-list>
</web-app>


simplecounter.jsp


<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.google.appengine.demos.taskqueueexamples.Counter"
%>

<html>
<head>
  <title>Simple Counter</title>
</head>
<body>

<h1>Count is: <%= Counter.getCount("thecounter") %>

<form action="/SimpleCounterWork" method="post">
  <input type="submit" value="Increment">
</form>

</body>
</html>


So when i  send a request to server through url from browser,Iam
getting a jsp page with output as  Count is 0  and also page is having
button named increment.when i click on button iam getting following
error

HTTP ERROR: 404

NOT_FOUND

RequestURI=/SimpleCounterWork

Powered by Jetty://

but i should get incremented count value but iam not getting it .so
please tell me how can i  correct this  particular error

 
thank u in advance

 
anu





so when i click on button  it  giving me an error







--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to