Click here to Skip to main content
15,867,771 members
Home / Discussions / Web Development
   

Web Development

 
GeneralRe: Internet Explorer 9 Preview Download Available to Developers (HTML, SVG, CSS, JavaScript) Pin
PHP_Guy17-Mar-10 8:01
PHP_Guy17-Mar-10 8:01 
QuestionOne defining reason ... SOE and CBSE Pin
NetQuestions17-Mar-10 4:09
NetQuestions17-Mar-10 4:09 
QuestionMinor problem/question with hide/reveal content javascript Pin
lvq68416-Mar-10 4:39
lvq68416-Mar-10 4:39 
AnswerRe: Minor problem/question with hide/reveal content javascript Pin
Not Active16-Mar-10 5:08
mentorNot Active16-Mar-10 5:08 
AnswerRe: Minor problem/question with hide/reveal content javascript Pin
PHP_Guy16-Mar-10 7:25
PHP_Guy16-Mar-10 7:25 
GeneralRe: Minor problem/question with hide/reveal content javascript Pin
lvq68416-Mar-10 22:43
lvq68416-Mar-10 22:43 
AnswerRe: Minor problem/question with hide/reveal content javascript Pin
T M Gray16-Mar-10 9:29
T M Gray16-Mar-10 9:29 
QuestionJSP page - fill bean - to servlet Pin
BASONJS16-Mar-10 0:00
BASONJS16-Mar-10 0:00 
Hi all,

I have been trying to find this out for 4 days straight, doing all types of research and yet I cannot find it, although it seems like one of the most fundamental things I can think of. I am new to jsps and servlets but not new to java, so please be patient with me

_____________________________________________________

SCENARIO:

1) I have an index.jsp page with a form with 1 field for the user to fill up.
2) I have a bean which I am trying to fill up from the index page itself.
3) I have a servlet that handles the request

_____________________________________________________

INDEX PAGE:
<%@ page import="com.java2s.*"%>
 
<html>
<body>
<jsp:useBean id="bean" class="com.java2s.bean" scope="session"/>
<jsp:setProperty name="bean" property="*"/>
<FORM METHOD=POST ACTION="MyServlet">
What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20><BR>
<P><INPUT TYPE=SUBMIT>
</FORM>
</body>
</html>



_____________________________________________________

BEAN:
package com.java2s;
 
public class bean {
    String username;
 
    public void setUsername( String value )
    {
        username = value;
    }
 
    public String getUsername() 
    { 
        return username; 
    }
}


_____________________________________________________

SERVLET:

package com.java2s;
 
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
public class MyServlet extends HttpServlet {
 
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException 
    {
 
        HttpSession session = request.getSession(true);
        // Get the bean from the session
        bean myBean = (bean)session.getAttribute("bean");
 
        // if the bean is not in session instantiate a new bean
        if (myBean == null)
        {
            myBean = new bean();
            myBean.setUsername("FAILED");
        }
 
        request.setAttribute("bean", myBean);
        request.getRequestDispatcher("test.jsp").forward(request, response);
    }
}

____________________________________________________

PROBLEM:

I get the bean in the servlet, that is to say:

bean myBean = (bean)session.getAttribute("bean"); actually returns an object and not null, thats not a problem.

The problem is that the username field is null. I have tried it with radio buttons and numerous other fields and they have all returned null.

If anybody please could help me it would be great. I highly appreciate any time you spend helping me out.

Thanks,
James
AnswerRe: JSP page - fill bean - to servlet [modified] Pin
hansoctantan5-Apr-10 16:46
professionalhansoctantan5-Apr-10 16:46 
QuestionJSF(JavaServer Faces) Session Management [modified] Pin
hansoctantan15-Mar-10 14:22
professionalhansoctantan15-Mar-10 14:22 
Question['HELP'] How can i share var. ? Pin
PHP_Guy15-Mar-10 8:31
PHP_Guy15-Mar-10 8:31 
AnswerRe: ['HELP'] How can i share var. ? Pin
Graham Breach15-Mar-10 9:04
Graham Breach15-Mar-10 9:04 
GeneralRe: ['HELP'] How can i share var. ? Pin
PHP_Guy15-Mar-10 9:14
PHP_Guy15-Mar-10 9:14 
Questionweb service, remoting and WCF Pin
NetQuestions14-Mar-10 20:43
NetQuestions14-Mar-10 20:43 
AnswerRe: web service, remoting and WCF Pin
SeMartens14-Mar-10 23:41
SeMartens14-Mar-10 23:41 
Questioncomponent oriented and service oriented Pin
NetQuestions14-Mar-10 18:52
NetQuestions14-Mar-10 18:52 
AnswerRe: component oriented and service oriented Pin
T M Gray16-Mar-10 12:09
T M Gray16-Mar-10 12:09 
GeneralRe: component oriented and service oriented [modified] Pin
NetQuestions16-Mar-10 20:30
NetQuestions16-Mar-10 20:30 
GeneralRe: component oriented and service oriented Pin
T M Gray17-Mar-10 4:35
T M Gray17-Mar-10 4:35 
GeneralRe: component oriented and service oriented Pin
NetQuestions17-Mar-10 17:56
NetQuestions17-Mar-10 17:56 
GeneralRe: component oriented and service oriented Pin
T M Gray18-Mar-10 8:54
T M Gray18-Mar-10 8:54 
GeneralRe: component oriented and service oriented Pin
NetQuestions22-Mar-10 17:59
NetQuestions22-Mar-10 17:59 
Questionautocomplete text box using javascript Pin
HemantDhodiya13-Mar-10 0:31
HemantDhodiya13-Mar-10 0:31 
AnswerRe: autocomplete text box using javascript Pin
Not Active13-Mar-10 3:28
mentorNot Active13-Mar-10 3:28 
AnswerRe: autocomplete text box using javascript Pin
Nitin S24-Mar-10 1:00
professionalNitin S24-Mar-10 1:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.