form bean and session attribute
Is two.jsp required? I'd rather combine it with one.jsp if possible.
Also, does it make sense to add the bean to the session for the servlet?
thufir@arrakis:~$
thufir@arrakis:~$
thufir@arrakis:~$ cat NetBeansProjects/rss-feeds/web/one.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page isELIgnored ="false" %>
<%@ page session="true"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<HTML>
<BODY>
<FORM METHOD="POST" ACTION="two.jsp">
<center>
<table>
<tr>
<td>feed:</td>
<td><INPUT TYPE=TEXT NAME=url SIZE="55"></td>
</tr>
<tr>
<td><INPUT TYPE="submit" value="Submit"/></td>
</tr>
</table>
</center>
</FORM>
</BODY>
</HTML>
thufir@arrakis:~$
thufir@arrakis:~$ cat NetBeansProjects/rss-feeds/web/two.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page isELIgnored ="false" %>
<%@ page session="true"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<jsp:useBean id="feed" class="thufir.Feed" scope="session"/>
<jsp:setProperty name="feed" property="*"/>
<jsp:forward page="/FeedServlet" />
thufir@arrakis:~$
thufir@arrakis:~$ cat
NetBeansProjects/rss-feeds/src/java/thufir/FeedServlet.java
package thufir;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class FeedServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Processes requests for both HTTP <code>GET</code> and
<code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
//FeedFormBean ffb = (FeedFormBean)
request.getAttribute("feed");
Feed ffb = (Feed) request.getSession().getAttribute("feed");
//Feed ffb = (Feed) request.getAttribute("feed");
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet FeedServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet FeedServlet at " +
request.getContextPath () + "</h1>");
out.println(ffb);
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods.
Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
*/
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
thufir@arrakis:~$
thufir@arrakis:~$
thanks,
Thufir