1.
public class OneServlet extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter out = resp.getWriter();
out.println("{\"statusCode\":\"301\", \"message\":\"Session Timeout! Please re-sign in!\"}");
}
}
2.
<?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_3_0.xsd"
id="WebApp_ID"
version="3.0">
<servlet>
<servlet-name>OneServlet</servlet-name>
<servlet-class>com.lesta.test.OneServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>OneServlet</servlet-name>
<url-pattern>/OneServlet</url-pattern>
</servlet-mapping>
</web-app>
3.
<form method="post" action="/OneServlet" class="pageForm required-validate" onsubmit="return validateCallback(this);">
<div class="pageFormContent" layoutH="56">
<p>
<label>E-Mail:</label>
<input class="required email" name="email" type="text" size="30" />
</p>
<p>
<label>客户名称:</label>
<input class="required" name="name" type="text" size="30" />
</p>
</div>
<div class="formBar">
<ul>
<li>
<div class="buttonActive"><div class="buttonContent"><button type="submit">保存</button></div></div>
</li>
<li>
<div class="button"><div class="buttonContent"><button type="Button" class="close">取消</button></div></div>
</li>
</ul>
</div>
</form>
老是请求servlet报404 也不知道为什么
不知道是不是action写的不对,可以试一试把前面的斜杠去掉
是不是你的OneServlet 只写了get方法doGet,没有写post方法,你提交的是post
你提交的方式是post,但是怎么在方法中只写了get的请求呢
像大家说的,把form里的method由post改成get试试。或者在你的servlet中增加doPost方法。
把doget改成services
我的情况和博主的情况一样,我将action中前面的斜杠去掉就可以了