gpt4 book ai didi

java - 405 此 url 不支持 http 方法 get

转载 作者:行者123 更新时间:2023-11-30 05:04:05 25 4
gpt4 key购买 nike

我编写了一个用于批准叶子的servlet。在此 servlet 中,我还编写了发送邮件的代码。因此,它显示 HTTP 405 错误。如果我删除发送邮件的代码,那么它不会显示错误,但我需要邮件代码。

package mis;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Properties;

import javax.jdo.PersistenceManager;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import javax.jdo.Query;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class approve extends HttpServlet {
private static final long serialVersionUID = 1L;

public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {

try{



HttpSession session = req.getSession(true);

PersistenceManager pm1 = PMF.get().getPersistenceManager();
Query query1 = pm1.newQuery(Leave_bal.class);
query1.setFilter("emp_Id == emp");
query1.declareParameters("String emp");
List<Leave_bal> results1 = (List<Leave_bal>)query1.execute(session.getAttribute("emp_Id").toString());

String plan="";
String unplan="";

String planleave_result="" ;
String unplanleave_result="";


for (Leave_bal e : results1)
{
plan=e.getplan_leave();
resp.getWriter().println("Planned_Leave"+plan);

unplan=e.getunplan_leave();
resp.getWriter().println("Unplanned:"+unplan);
}

int plan_leave=Integer.parseInt(plan);
int unplan_leave=Integer.parseInt(unplan);


String ID=req.getParameter("id");
resp.getWriter().println(ID);
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(Leave_detail.class);
query.setFilter("id == ID");
query.declareParameters("String ID");
List<Leave_detail> results = (List<Leave_detail>)query.execute(ID);

String plan_detail="";


String duration="";
for (Leave_detail e : results)
{
plan_detail=e.getLeave_Type();
duration=e.getdurtn();
//f=e.getfrom();
//t=e.getto();
}

resp.getWriter().println("duration "+duration);
resp.getWriter().println("Planned_selected "+plan_detail);


int duration_integer=Integer.parseInt(duration);
resp.getWriter().println("duration "+duration_integer);


//String duration=req.getParameter("date");
// resp.getWriter().println("diffrence:"+duration);
//int workingdays=Integer.parseInt(duration);

//String Leave = req.getParameter("a");
// resp.getWriter().println("planned:"+Leave);

if(plan_detail.equals("UNPLAN"))
{
unplan_leave=unplan_leave-duration_integer;
unplanleave_result=String.valueOf(unplan_leave);
planleave_result=plan;
resp.getWriter().println("Planned After Change"+unplanleave_result);
//st="Applied";

}
if(plan_detail.equals("PLAN"))
{
plan_leave= plan_leave-duration_integer;
planleave_result=String.valueOf(plan_leave);
resp.getWriter().println("Planned After Change"+planleave_result);
unplanleave_result=unplan;

}

if(plan_detail.equals("LWP"))
{
plan_leave= plan_leave-duration_integer;
planleave_result=String.valueOf(plan_leave);
resp.getWriter().println("Planned After Change"+planleave_result);
unplanleave_result=unplan;

}

if(plan_detail.equals("Onduty"))
{
planleave_result=plan;
unplanleave_result=unplan;

}




Leave_detail status_update = pm.getObjectById(Leave_detail.class,ID);
status_update.setstatus("Approved");
pm.makePersistent(status_update);

Leave_bal ed1=new Leave_bal(session.getAttribute("emp_Id").toString(),planleave_result,unplanleave_result);

pm.makePersistent(ed1);



//code for mail

RequestDispatcher dispatcher = getServletConfig ( ) .getServletContext ().getRequestDispatcher("/MailServiceapply");
dispatcher.forward (req, resp) ;

pm.close();
}
catch(Exception a )
{
resp.getWriter().println(a .getMessage());
} finally{

}
resp.sendRedirect("hr.jsp#LMS");
}
}

最佳答案

This thread Java 论坛上提供了有关此错误的一些提示,例如

  • HTML 表单调用 POST 操作,而 servlet 未实现 doPost ( direct link )
  • 初始 HTML 表单未在 web.xml 文件中声明(或拼写错误)( direct link )

关于java - 405 此 url 不支持 http 方法 get,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5700861/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com