标签: servlets

Servlet接口不是javax.servlet.Servlet

嗨,这个bug无法追踪 - 需要帮助.

我正在使用谷歌应用程序引擎和编写如下的rpc servlet

<!-- Servlets -->
<servlet>
    <servlet-name>RealEstate_Service</servlet-name>
    <servlet-class>com.app.realestate.navi.client.RealEstateService</servlet-class>

</servlet>
<servlet-mapping>
    <servlet-name>RealEstate_Service</servlet-name>
    <url-pattern>/real_estate/realEstateService/</url-pattern>
</servlet-mapping> 
Run Code Online (Sandbox Code Playgroud)

RealEstateService

@RemoteServiceRelativePath("realEstateService")
public interface RealEstateService extends RemoteService {
ArrayList<ProjectDetails> getProjectDetails();
}

public interface RealEstateServiceAsync {
    public void getProjectDetails(AsyncCallback<ArrayList<ProjectDetails>> callback);
}
Run Code Online (Sandbox Code Playgroud)

RealEstateServiceImpl

@SuppressWarnings("serial")
public class RealEstateServiceImpl extends RemoteServiceServlet implements RealEstateService{

      private static final String[] contactsFirstNameData = new String[] {
          "Hollie", "Emerson", "Healy", "Brigitte", "Elba", "Claudio",
          "Dena", "Christina", "Gail", "Orville", "Rae", "Mildred",
          "Candice", "Louise", "Emilio", "Geneva", "Heriberto", "Bulrush", 
          "Abigail", "Chad", "Terry", "Bell"};

      private final String[] contactsLastNameData …
Run Code Online (Sandbox Code Playgroud)

gwt google-app-engine servlets

1
推荐指数
1
解决办法
4011
查看次数

使用HTML在JSP中调用java scriptlet

我试图找到一种方法来java code使用HTML表单调用JSP中的一部分

  <form method="get" action="invokeMe()">

       <input type="submit" value="click to submit" />

  </form>


  <%
     private void invokeMe(){
       out.println("He invoked me. I am happy!");   
     }
  %>
Run Code Online (Sandbox Code Playgroud)

上面的代码在JSP中.我希望在提交时运行scriptlet

我知道代码看起来非常糟糕,但我只想掌握这个概念......以及如何去实现它.

谢谢

java jsp servlets scriptlet

1
推荐指数
1
解决办法
4079
查看次数

文件是否附加在文件字段中?

我有以下代码:

if (formItems != null && formItems.size() > 0) {
    // iterates over form's fields
    for (FileItem item : formItems) {
        // processes only fields that are not form fields
        if (!item.isFormField()) {
            String fileName = new File(item.getName()).getName();
            String filePath = uploadPath + File.separator + fileName;
            File storeFile = new File(filePath);

            // saves the file on disk
            item.write(storeFile);
            session.setAttribute("image", fileName);
        }
        // processes only form fields
        else {
            String fieldname = item.getFieldName();
            String fieldvalue = item.getString();
            session.setAttribute(fieldname, fieldvalue);
        }
    } …
Run Code Online (Sandbox Code Playgroud)

java servlets file-upload apache-commons-fileupload

1
推荐指数
1
解决办法
3843
查看次数

单击JSP上的提交后,URL错误

我是JSP的新手,我正处理一个令人困惑的问题.我有一个JSP表单,位于我的web-app中名为"admin"的子文件夹中(名为"CMS").

CMS/admin/display_content.jsp  
Run Code Online (Sandbox Code Playgroud)

我的表单具有以下action和method属性值

<form action="/deleteContent" method="POST"> 
Run Code Online (Sandbox Code Playgroud)

/ deleteContent是名为DeleteContentServlet的servlet的URL模式.它只是从DB中删除用户选择.无论如何,我的问题是,一旦我点击提交,我注意到我的地址栏中输入的URL不正确.而不是得到

http://localhost:8080/CMS/deleteContent 
Run Code Online (Sandbox Code Playgroud)

我明白了

http://localhost:8080/deleteContent 
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题 ?当我有子文件夹时,是否只用于导入的文件?谢谢.

java jsp servlets

1
推荐指数
1
解决办法
1191
查看次数

JSON响应以文本形式返回

我在我的java servlet中编写了如下JSON响应,其中JObject是创建的JSON对象

response.setContentType("application/json; charset=UTF-8");
PrintWriter printout = response.getWriter();
printout.print(JObject);
printout.flush();
Run Code Online (Sandbox Code Playgroud)

但它在接收方以文本/普通方式收到

[Server: Apache-Coyote/1.1, ETag: W/"XXXXXXXXXX", Last-Modified: Tue, 04 Jun 2013 10:42:31 GMT, Content-Type: text/plain, Content-Length: 2573, Date: Tue, 04 Jun 2013 10:44:01 GMT]
Run Code Online (Sandbox Code Playgroud)

如何获得确切的JSON响应?如果我JSON在同一台机器上编写响应,即可获取JSON数据.但是如果我JSON在另一台服务器上编写响应,它会返回text/plain.

这是JObject:

JSONObject JObject = new JSONObject(); 
JObject.put("Response", "1"); 
JObject.put("Message", "Client unauthorized"); 
Run Code Online (Sandbox Code Playgroud)

java json servlets httpresponse

1
推荐指数
1
解决办法
2万
查看次数

如何在servlet中运行不同的线程?

如何从servlet运行不同的线程?我init()在servlet 的方法中有以下代码.

FileThread myThread = new FileThread();
myThread.start();
myThread.run();     
Run Code Online (Sandbox Code Playgroud)

FileThread应该看到一些文件夹来检查文件是否被更改.所以这个线程在循环中运行.但它不像我预期的那样有效.它冻结(服务器不返回HTML)服务器的服务.

我希望这个线程在后台运行,而不是干扰servlet的进程.我怎么能得到这个?

java multithreading servlets

1
推荐指数
2
解决办法
3680
查看次数

从登录参数创建用户对象

我正在尝试在用户登录后使用所有用户字段创建用户对象,以便我可以从用户的类中检索任何给定的属性.这是User类.

public class User  {

private String username;
private String password;
private String f_name;
private String l_name;
private String email;
private String dob;
private int user_id;

public User(){}

public User(String username, String password)
{
    this.username = username;
    this.password = password;
}

public User(String username, String password, String f_name, String l_name, String email, String dob, int user_id)
{
    this.f_name = f_name;
    this.l_name = l_name;
    this.username = username;
    this.password = password;
    this.email = email;
    this.dob = dob;
    this.user_id = user_id;
}
Run Code Online (Sandbox Code Playgroud)

我有所有领域的getter和setter.所有用户字段也存储在Oracle数据库中. …

java servlets jdbc

1
推荐指数
1
解决办法
5088
查看次数

Java - getServletContext().getAttribute()返回null

我有一个MainServletContextimplements ServletContextListener存储属性

public void contextInitialized(ServletContextEvent sce) {

    ServletContext servletContext = sce.getServletContext();

    // successfully get a non-null stockMap
    servletContext.setAttribute("stockMap", stockMap);
}
Run Code Online (Sandbox Code Playgroud)

我宣布它web.xml,它看起来像

  <listener>
        <listener-class>controller.MainServletContext</listener-class>
  </listener>
Run Code Online (Sandbox Code Playgroud)

现在我想stockMap从servlet类中获取它

Map<SimpleStock, Stock> stockMap = (Map<SimpleStock, Stock>) getServletContext().getAttribute("stockMap");
Run Code Online (Sandbox Code Playgroud)

我有一个NullPointerException.我可以问一下是否有任何缺失的步骤?

谢谢.

堆栈跟踪

java.lang.NullPointerException
javax.servlet.GenericServlet.getServletContext(GenericServlet.java:125)
controller.TopTenServlet.service(TopTenServlet.java:91)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
Run Code Online (Sandbox Code Playgroud)

我的Servlet init方法

@Override
public void init(ServletConfig config) throws ServletException {
    this.servletConfig = config;
}
Run Code Online (Sandbox Code Playgroud)

java servlets

1
推荐指数
1
解决办法
6614
查看次数

maven-执行货物失败:开始

我正在尝试cargo在servlet项目中配置自动部署,并且pom.xml文件中包含以下内容:

    <dependency>
      <groupId>org.codehaus.cargo</groupId>
      <artifactId>cargo-core-api-module</artifactId>
      <version>1.4.3</version>
    </dependency>
     <!--
     <dependency>
       <groupId>org.codehaus.cargo</groupId>
       <artifactId>cargo-core-container-tomcat</artifactId>
       <version>1.4.2-SNAPSHOT</version>
    </dependency>
        -->     
    <dependency>         
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <version>1.4.2</version>
    </dependency>
    <build>
     <plugins>
       <!-- cargo plugin  -->
  <plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <configuration>
        <container>
            <containerId>tomcat6x</containerId>
            <type>remote</type>
            <systemProperties>
                <cargo.jvmargs>-XX:MaxPermSize=256M -Xmx1024m</cargo.jvmargs>
            </systemProperties>
        </container>
        <configuration>
            <type>runtime</type>
            <properties>
                <cargo.hostname>${remote.hostname}</cargo.hostname>
                <cargo.protocol>${remote.protocol}</cargo.protocol>
                <cargo.servlet.port>9000</cargo.servlet.port>
                <cargo.tomcat.manager.url>http://localhost:9000/manager</cargo.tomcat.manager.url>
                <cargo.remote.username>user</cargo.remote.username>
                <cargo.remote.password>pass</cargo.remote.password>
            </properties>
        </configuration>
        <deployer>
            <type>remote</type>
            <deployables>
                <deployable>
                    <groupId>${groupId}</groupId>
                    <artifactId>${artifactId}</artifactId>
                    <type>war</type>
                    <properties>
                        <context>latest</context>
                    </properties>
                </deployable>
            </deployables>
        </deployer>
    </configuration>
</plugin>
<!-- End cargo plugin -->
     </plugins>
     <build>>
Run Code Online (Sandbox Code Playgroud)

当我尝试通过以下方式开始装货时,出现mvn clean cargo:start构建失败:

[ERROR] Failed …
Run Code Online (Sandbox Code Playgroud)

java deployment servlets cargo maven

1
推荐指数
1
解决办法
5150
查看次数

jsp:点击html链接时删除文件

我想在点击jsp页面中的HTML链接后删除文件.

以下是我的jsp代码:

<%
File f=new File("c:\\Folder\\1.jpg");
f.delete();
%>
Run Code Online (Sandbox Code Playgroud)

href应该在HTML代码中使用什么?

<a href......>Delete me </a>
Run Code Online (Sandbox Code Playgroud)

java jsp servlets

1
推荐指数
1
解决办法
9255
查看次数