我想使用 Java Servelet 制作菜单,我试试这个:
dash_menu.java
package br.com.pw5k.nav;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URLDecoder;
import java.net.URLEncoder;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class dash_menu extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
//response.setContentType("text/html;charset=UTF-8");
String outHtml = "<form> Dashboard Menu <br> </form>";
outHtml = URLDecoder.decode( outHtml, "text/html" ); // and finally : Hélène
//request.setCharacterEncoding("utf-8");
request.setAttribute("html_insert", outHtml);
RequestDispatcher rd = request.getRequestDispatcher("/faces/dashboard.xhtml");
rd.forward(request, response);
}
// @Override
// protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//
// PrintWriter imprimir = response.getWriter();
//
// imprimir.println("Método POST foi disparado!");
// }
}
仪表板.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:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
<ui:composition template="./logged_template.xhtml">
<ui:define name="body">
<h:form>
Dashboard!
<br/>
<h:commandButton value="Perfil" action="user_control.xhtml"/>
</h:form>
#{html_insert}
</ui:define>
</ui:composition>
</html>
当我尝试调用时:“dash_menu”:
http://localhost:8084/PW5K_App/faces/dash_menu
but output change html tags "< >" by "< >"
显示输出
<form> Dashboard Menu <br> </form>
HTML 检查代码
<form> Dashboard Menu <br> </form>
现在有什么办法解决这个问题吗?