我正在尝试从表单中调用 servlet。我在调用 servlet 的 Web 应用程序中有 xhtml,但未显示来自 servlet 的响应。按下提交按钮后会显示原始的 xhtml。我为 servlet 响应尝试了不同的替代方案,但每次都得到相同的结果。
xhtml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:ejstreegrid="https://unfccc.int/nais/ejstreegrid"
xmlns:grid="http://java.sun.com/jsf/composite/gridcomp"
xmlns:nais="http://java.sun.com/jsf/composite/naiscomp">
<body>
<ui:composition template="/templateForm.xhtml">
<ui:define name="title">Some title</ui:define>
<ui:param name="currentPage" value="somepage.xhtml" />
<ui:define name="body">
<h2>the name to be added</h2><br/><br/>
<form action="someServlet" method="post">
<input type="text" name="someName" />
<input type="submit" />
</form>
</ui:define>
</ui:composition>
</body>
</html>
Web 应用程序中的 servlet 被调用:
package netgui.servlet;
import java.io.IOException;
import java.util.Enumeration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class someServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public someServlet() {
super();
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}
private void processRequest(HttpServletRequest request,
HttpServletResponse response) throws IOException {
try {
response.getWriter().write("some response");
} catch (Exception e) {
logger.error(e.getMessage());
e.printStackTrace();
response.getWriter().println("Error: " + e.getMessage());
}}}
我还有一个 menu.xhtml 正在调用 xhtml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<body>
<script type="text/javascript">
$(document).ready(function() {
$("#btn").click(function() {
$("#upload").click();
return false;
});
});
</script>
<ui:composition>
<div id="navigation_bar">
<ul id="topbarleft">
<c:choose>
<c:when test="${currentPage=='somepage.xhtml'}">
<li><b>Other (Please Specify) Two</b></li>
</c:when>
<c:otherwise>
<li><h:outputLink value="somepage.jsf">
<h:outputText value="some page" />
</h:outputLink></li>
</c:otherwise>
</c:choose>
</ul>
</div>
</ui:composition>
</body>
</html>
有什么想法可能是错的吗?jsf中是否有一些特殊的格式可以将表单提交给servlet?带小脸?