相关疑难解决方法(0)

如何在基于servlet的Web应用程序中运行后台任务?

我正在使用Java,我想在我的应用程序中保持servlet不断运行,但我不知道怎么做.我的servlet有一个方法,它每天从数据库中提供用户的计数以及整个数据库中用户的总数.所以我想保持servlet不断运行.

multithreading servlets background-process java-ee scheduledexecutorservice

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

Servlet返回"HTTP状态404请求的资源(/ servlet)不可用"

我的文件WebContent/jsps夹中的JSP文件中有一个HTML表单.我servlet.javasrc文件夹中的默认包中有一个servlet类.在我web.xml的映射为/servlet.

action在HTML表单的属性中尝试了几个URL :

<form action="/servlet">
Run Code Online (Sandbox Code Playgroud)
<form action="/servlet.java">
Run Code Online (Sandbox Code Playgroud)
<form action="/src/servlet.java">
Run Code Online (Sandbox Code Playgroud)
<form action="../servlet.java">
Run Code Online (Sandbox Code Playgroud)

但这些都不起作用.他们都在Tomcat 6/7/8中继续返回如下所示的HTTP 404错误:

HTTP状态404 - /servlet

描述:请求的资源(/ servlet)不可用.

或者如下面的Tomcat 8.5/9:

HTTP状态404 - 未找到

消息:/ servlet

描述:源服务器没有找到目标资源的当前表示,或者不愿意透露存在该资源

为什么不起作用?

html forms jsp servlets http-status-code-404

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

HTTP状态405 - 此URL URL servlet不支持HTTP方法POST

我无法让页面工作.我有我的表单方法发布和我的servlet实现doPost().但是,它一直向我显示我不支持POST方法.

我只是想做一个简单的网站,并将值插入我的MySQL数据库.

*type Status report
message HTTP method POST is not supported by this URL
description The specified HTTP method is not allowed for the requested resource (HTTP method POST is not supported by this URL).*
Run Code Online (Sandbox Code Playgroud)

静态页面:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN"
        "http://www.wapforum.org/DTD/xhtml-mobile10.dtd" >

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>XHTML Mobile Profile Document</title>
        <!-- 
            Change href="style.css" below to the file name and
            relative path or URL of your external style sheet.
          --> 
        <link …
Run Code Online (Sandbox Code Playgroud)

java servlets

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

HTTP状态405 - 此URL不支持HTTP方法GET

下面的代码来自一本书,所以它不会出错.但我不知道如何解决这个错误.当删除方法doGet()时,同样的错误!

"HTTP状态405 - 此URL不支持HTTP方法GET"

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class PDFServlet extends HttpServlet{
private static final long serialVersionUID = 1L;
@Override 
protected void doGet(HttpServletRequest request,HttpServletResponse response) 
throws IOException,ServletException{
    this.doPost(request,response);
}
@Override 
protected void doPost(HttpServletRequest request,HttpServletResponse response) 
                                   throws IOException,ServletException{
    response.setContentType("application/pdf");
    ServletOutputStream out=response.getOutputStream();
    File pdf=null;
    BufferedInputStream buf=null;
    try{
        pdf=new File("C:\\Users\\lk\\Desktop\\Desktop\\ example.pdf");
        response.setContentLength((int)pdf.length());
        FileInputStream input=new FileInputStream(pdf);
        buf=new BufferedInputStream(input);
        int readBytes=0;
        while((readBytes=buf.read())!=-1)    out.write(readBytes);
    }catch(IOException e){
        System.out.println("file not found!");
    }finally{
        if(out!=null) …
Run Code Online (Sandbox Code Playgroud)

servlets http-get http-status-code-405

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

从 javascript 到 java servlet 的 HTTP POST

如何通过 JavaScript 将参数发布到 Java Servlet?

这是我的 html 代码,它有效:

<div id="loginPanel">
<form action="/login" method="POST" class="form">
    <label>Login:</label>
    <input type="text" name="login" id="login">
    <label>Password:</label>
    <input type="text" name="password" id="password">
    <div id="loginLower">
        <input type="checkbox"><label memory="memory">Remember me</label>
        <input type="submit" value="Login">
    </div>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)

现在,我想散列密码和 POST 到 /login hashPassword 像这样:

<form onsubmit="post()">
    <label>Login:</label>
    <input type="text" name="login" id="login">
    <label>Password:</label>
    <input type="text" name="password" id="password">
    <div id="loginLower">
        <input type="checkbox"><label memory="memory">Remember me</label>
        <input type="submit" value="Login">
    </div>
</form>

<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/md5.js"></script>

<script>
function post(){
 var passhash = CryptoJS.MD5(document.getElementById("password").value);
//post to /login login and passhash …
Run Code Online (Sandbox Code Playgroud)

javascript java jsp servlets

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

此URL虽然执行doGet,但不支持HTTP方法GET

public class RoarHistoryUpdate extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException{
        super.doGet(request, response);
        System.out.println("do Get");
        response.setContentType("text/html");
        response.getOutputStream().print("Success");
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的Servlet.它在web.xml中注册如下:

  <servlet>
      <display-name>RoarHistoryUpdateServlet</display-name>
      <servlet-name>RoarHistoryUpdateServlet</servlet-name>
      <servlet-class>de.ulm.uni.vs.avid.roary.servlets.RoarHistoryUpdate</servlet-class>
  </servlet>
  <servlet-mapping>
      <servlet-name>RoarHistoryUpdateServlet</servlet-name>
      <url-pattern>/Roary/UpdateServlet</url-pattern>
  </servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

当我转到URL http://localhost:8080/Roary-JSP/Roary/UpdateServlet它说HTTP Status 405 - HTTP method GET is not supported by this URL

有趣的是我得到了do Get登录到我的控制台.所以它实际上找到了doGet- 方法.

我使用的是GlassFish Server开源版3.1.2.2

java servlets glassfish-3

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

简单 Servlet HTTP 状态 405 - 此 URL 不支持 HTTP 方法 GET

我开始研究servlet。代码服务程序:

package arver;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by 35717 on 30.03.2016.
 */
public class MainServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
        PrintWriter out = resp.getWriter();
        out.print("servlet");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
Run Code Online (Sandbox Code Playgroud)

文件 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"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
             version="3.0">

        <servlet>
            <servlet-name>MainServlet</servlet-name>
            <servlet-class>arver.MainServlet</servlet-class>
        </servlet>

        <servlet-mapping>
            <servlet-name>MainServlet</servlet-name> …
Run Code Online (Sandbox Code Playgroud)

java servlets

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